【问题标题】:How to increase nginx timeout for upstream uWSGI server?如何增加上游 uWSGI 服务器的 nginx 超时?
【发布时间】:2016-06-01 14:21:02
【问题描述】:

使用的堆栈:

Nginx -> Uwsgi (代理通过) -> Django

我有一个 API 需要大约 80 秒来执行查询。 Nginx 在 60 秒后关闭与上游服务器的连接。这是在 nginx 错误日志中发现的:

upstream prematurely closed connection while reading response header from upstream

uWSGI 和 django 应用程序日志没有显示任何奇怪的东西。

这是我的 nginx 配置:

server {
   listen 80;
   server_name xxxx;
   client_max_body_size 10M;

   location / {
       include         uwsgi_params;
    proxy_pass http://127.0.0.1:8000;
    proxy_connect_timeout 10m;
    proxy_send_timeout   10m;
     proxy_read_timeout   10m;
     proxy_buffer_size    64k;
     proxy_buffers     16 32k;
     proxy_busy_buffers_size 64k;
     proxy_temp_file_write_size 64k;
     proxy_pass_header Set-Cookie;
     proxy_redirect     off;
     proxy_hide_header  Vary;
    proxy_set_header   Accept-Encoding '';
     proxy_ignore_headers Cache-Control Expires;
     proxy_set_header   Referer $http_referer;
     proxy_set_header   Host   $host;
     proxy_set_header   Cookie $http_cookie;
     proxy_set_header   X-Real-IP  $remote_addr;
     proxy_set_header X-Forwarded-Host $host;
     proxy_set_header X-Forwarded-Server $host;
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
   }
}

如何增加超时,我尝试设置 proxy_pass 超时变量,但它们似乎没有工作。

【问题讨论】:

    标签: nginx uwsgi


    【解决方案1】:

    好的,所以设法通过将proxy_pass 替换为uwsgi_pass 来解决此问题

    这就是我的 nginx conf 现在的样子:

    server {
        listen 80;
        server_name xxxxx;
        client_max_body_size 4G;
    
        location /static/ {
             alias  /home/rmn/workspace/mf-analytics/public/;
        }
    
        location / {
            include uwsgi_params;
            uwsgi_pass unix:/tmp/uwsgi_web.sock;
            uwsgi_read_timeout 600;
        }
    }
    

    我必须在我的 uwsgi ini 文件中设置 socket 参数。

    由于某种原因,proxy_pass 超时不会生效。

    【讨论】:

    • 因为你使用的是 uwsgi_pass 而不是 proxy_pass。
    猜你喜欢
    • 2018-08-17
    • 2018-07-31
    • 1970-01-01
    • 1970-01-01
    • 2013-09-21
    • 1970-01-01
    • 1970-01-01
    • 2016-02-12
    • 2023-02-22
    相关资源
    最近更新 更多