HTTPConnectionPool(host='x.x.x.x', port=y):读取超时。 (read timeout=None) 在 nginx 服务器上?

HTTPConnectionPool(host='x.x.x.x', port=y): Read timed out. (read timeout=None) on nginx server?

在我的 python 脚本中有多个 API 调用并且 APIs 在同一个应用程序中! 我正在使用 django 框架! 通过 python3 manage.py runserver 它运行良好!

但是在带有 nginx 服务器、supervisor、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;
}

谢谢!希望这对遇到同样问题的人有所帮助!