[Django]-110: Connection timed out (Nginx/Gunicorn)

94๐Ÿ‘

You could try upgrading the timeout for your proxy pass in Nginx by adding:

proxy_connect_timeout 75s;
proxy_read_timeout 300s;

on /var/nginx/sites-available/[site-config] or /var/nginx/nginx.conf if you want to increase the timeout limite on all sites served by nginx.

You must add --timeout 300 as well to your gunicorn process/config.

This solved my problems in the past with bigger uploads.

๐Ÿ‘คfijter

46๐Ÿ‘

This is not an nginx timeout, but probably a Gunicorn timeout. Gunicorn defaults to a 30 second timeout.

In general, you should fix this by not having an endpoint that takes longer than 30 seconds to return, but if it is a seldom used endpoint, you can also just increase the gunicorn timeout.

If you do this, you should probably also increase the number of gunicorn worker processes as well.

To increase the timeout and workers for gunicorn, you can add the following command-line options on start:

gunicorn --timeout 120 --workers <NUMBER OF WORKER YOU WANT>
๐Ÿ‘คddipasquo

16๐Ÿ‘

We had the same problem using Django+nginx+gunicorn.
From Gunicorn documentation we have configured the graceful-timeout that made almost no difference.

After some testings, we found the solution, the parameter to configure is: timeout
(And not graceful timeout). It works like a clock..

So, Do:

1) open the gunicorn configuration file

2) set the TIMEOUT to what ever you need โ€“ the value is in seconds

NUM_WORKERS=3
TIMEOUT=120

exec gunicorn ${DJANGO_WSGI_MODULE}:application \
--name $NAME \
--workers $NUM_WORKERS \
--timeout $TIMEOUT \
--log-level=debug \
--bind=127.0.0.1:9000 \
--pid=$PIDFILE
๐Ÿ‘คAmit Talmor

0๐Ÿ‘

If you are using reverse proxy with Nginx and running the Django app using Gunicorn, try to adjust Gunicorn timeout parameter and proxy_read_timeout parameter from default values.

๐Ÿ‘คFathima Shaibal

-2๐Ÿ‘

This might help someone with similar problem.

I was getting timeout error from nginx and gunicorn on my Django application. Since I was getting the timeout error from nginx, I couldnโ€™t see the real error from Django. After adding the new timeout like fijter suggested. I could see that the error was in the settings.py file.

If you set the DEBUG to False, and didnโ€™t add the domain name in the ALLOWED_HOSTS you might get this error.

I just added the domain in the ALLOWED_HOSTS in settings.py and the error was gone.

Very simple solution!

๐Ÿ‘คRLott

Leave a comment