在我的python脚本中,有多个API调用,并且API在同一应用程序中!我正在使用django框架!通过python3 manage.py runserver
运行正常!
但是在具有nginx服务器,主管,gunicorn的centos7 VM中,调用第三个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:
需要帮助
终于找到了解决方法!
实际上是因为gunicorm和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;
}
谢谢!希望如果有人遇到同样的问题,这会有所帮助!