aliasav
aliasav

Reputation: 3168

How to increase nginx timeout for upstream uWSGI server?

Stack used:

Nginx -> Uwsgi (proxy passed) -> Django

I have an API that takes aroundn 80 seconds to execute a query. Nginx closes the connection with the upstream server after 60 seconds. This was found in the nginx error log:

upstream prematurely closed connection while reading response header from upstream

The uWSGI and django application logs do not show anything weird.

This is my nginx configuration:

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;
   }
}

How do I increase the timeout, I have tried settings the proxy_pass timeout variables but they do no seem to be working.

Upvotes: 0

Views: 4858

Answers (1)

aliasav
aliasav

Reputation: 3168

Okay, so managed to solve this issue by replacing proxy_pass with uwsgi_pass

This is how my nginx conf looks now:

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;
    }
}

And I had to set the socket parameter in my uwsgi ini file.

For some reason, the proxy_pass timeouts just wouldnt take effect.

Upvotes: 2

Related Questions