在我的 python 腳本中,有多個 API 調用,并且 API 在同一個應用程序中!我正在使用 django 框架!通過 python3 manage.py runserver 它工作正常!但是在帶有 nginx 服務器、主管、gunicorn 的 centos7 虛擬機中,調用第三個 API 后它無法正常工作!出現了這個錯誤:The complete exception is provided below:<class 'requests.exceptions.ReadTimeout'>HTTPConnectionPool(host='x.x.x.x', port=y): Read timed out. (read timeout=None)在 nginx 錯誤日志中只有這個錯誤:[error] 12020#12020: *133 upstream prematurely closed connection while reading response header from upstream, client:需要一些幫助
1 回答

子衿沉夜
TA貢獻1828條經驗 獲得超3個贊
終于我找到了解決辦法!
其實是因為gunicom和nginx的超時。
我的腳本需要 30 多秒,所以請更新我的 gunicorn 配置文件!
這是配置:
[program:project]
command = gunicorn -c /opt/project/gunicorn_config.py project.wsgi -t 300
directory = project directory
user = user
nginx配置也需要添加這個代理設置:
location / {
proxy_pass http://127.0.0.1:8001;
proxy_set_header X-Forwarded-Host $server_name;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"';
proxy_read_timeout 300s;
proxy_connect_timeout 300s;
}
謝謝!如果有人遇到同樣的問題,希望這會有所幫助!
添加回答
舉報
0/150
提交
取消