Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx timeouts when uWSGI takes long to process request

I have Nginx + uWSGI for Python Django app.

I have the following in my 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; } 

but for long running requests on uWSGI which takes about 1 minute to complete I get a timeout error in Nginx error log as below:

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"

I have already set the header time out and the uWSGI send/read timeouts to 5 mins, can someone please tell me what I can do to overcome this?

like image 334
anishek Avatar asked Apr 22 '13 07:04

anishek


People also ask

Is NGINX required for uWSGI?

That's the simple answer, anyway -- you don't need it. uWSGI is itself a capable server.

Is uWSGI multithreaded?

If you need threads, remember to enable them with enable-threads . Running uWSGI in multithreading mode (with the threads options) will automatically enable threading support.

What is uWSGI in NGINX?

Nginx implements a uwsgi proxying mechanism, which is a fast binary protocol that uWSGI can use to talk with other servers. The uwsgi protocol is actually uWSGI's default protocol, so simply by omitting a protocol specification, it will fall back to uwsgi .

How does uWSGI server work?

The UWSGI server is responsible for loading your Flask application using the WSGI interface. You can actually make UWSGI listen directly to requests from the internet and remove NGINX if you like, although it's mostly used behind a reverse proxy.


2 Answers

The configuration that solves the problem is:

location / {     include uwsgi_params;     uwsgi_pass   127.0.0.1:9001;     uwsgi_read_timeout 300;     index  index.html index.htm; } 

The reason the above configuration in the question did not work for us because unfortunately in our machine multiple paths had nginx.conf file. We were working with the conf at the wrong path.

To correctly figure out which path your nginx is picking up the configuration from run:

nginx -V  # V is caps 

this will have a --conf-path=[] which will tell you exactly from where it is picking up the configuration from.

I recently found the above nginx -V to not give the right info. I will leave the above just in case others find it useful.

like image 122
anishek Avatar answered Sep 21 '22 08:09

anishek


Solved by changing the following Nginx config

proxy_connect_timeout 300; proxy_read_timeout    300;   client_body_timeout   300; client_header_timeout 300; keepalive_timeout     300; 

And UWSGI setting

http-timeout = 300 // or 'socket-timeout = 300' depending on uwsgi setting 
like image 31
vinayak hegde Avatar answered Sep 19 '22 08:09

vinayak hegde