我有用于 Python Django 应用程序的 Nginx + uWSGI。
我的 nginx.conf
中有以下内容:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
uwsgi_read_timeout 1800;
uwsgi_send_timeout 300;
client_header_timeout 300;
proxy_read_timeout 300;
index index.html index.htm;
}
但是对于 uWSGI 上长时间运行的请求(大约需要 1 分钟才能完成),我在 Nginx 错误日志中收到如下超时错误:
2013/04/22 12:35:56 [error] 2709#0: *1 upstream timed out (110: Connection timed out) while reading response header from upstream, client: xx.xx.xx.xx, server: , request: "GET /entity/datasenders/ HTTP/1.1", upstream: "uwsgi://127.0.0.1:9001", host: "xxx.xx.xx.x"
我已经将 header 超时和 uWSGI 发送/读取超时设置为 5 分钟,有人可以告诉我如何克服这个问题吗?
最佳答案
解决问题的配置是:
location / {
include uwsgi_params;
uwsgi_pass 127.0.0.1:9001;
uwsgi_read_timeout 300;
index index.html index.htm;
}
问题中的上述配置对我们不起作用的原因是不幸的是,在我们的机器中多个路径都有 nginx.conf
文件。我们与 session 的合作方向是错误的。
要正确找出 nginx 从运行中获取配置的路径:
nginx -V # V is caps
这将有一个--conf-path=[]
,它将准确地告诉您它从哪里获取配置。
我最近发现上面的 nginx -V
没有提供正确的信息。我将保留上述内容,以防其他人发现它有用。
关于当 uWSGI 需要很长时间来处理请求时,Nginx 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16141610/