当 uWSGI 需要很长时间来处理请求时,Nginx 超时

标签 nginx configuration uwsgi connection-timeout

我有用于 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/

相关文章:

django - Nginx + Gunicorn + Django 高延迟

wordpress - nginx 反向代理到 apache-wordpress 可以工作,但到外部 url 的 proxy_pass 失败

python - 木星 SSL : WRONG_VERSION_NUMBER

visual-c++ - fatal error LNK1112 : module machine type 'X86' conflicts with target machine type 'AMD64'

tomcat - 发布请求的 Elastic Beanstalk CORS 配置

configuration - 配置 VSCode 执行不同的任务

python - uwsgi_response_write_body_do() 超时——但是 uwsgi_read_timeout 没有帮助(x-post)

python - 无法登录到 uwsgi 控制台

python - 从 python 以编程方式更改 nginx 配置文件的任何好方法?

http - 不需要的 HTTPS -> 使用 nginx + uwsgi + flask app 进行 HTTP 重定向