1

I am getting a 502 Bad Gateway error and am realizing it is probably a timeout from Gunicorn.

I'm attempting to increase Gunicorn's default timeout from 30 seconds to something higher, probably 5 minutes, but despite my config file change, the time out is still happening at 30 seconds.

I realize the first order of action is to resolve the server-side process so it doesn't take longer than 30 seconds.

In this case, however, I'm running a large sql stored procedure report and it sometimes takes longer than 30 seconds because of the amount of data being churned.

Below are my nginx and gunicorn config files.

Thanks for any help!


gunicorn.conf:

description "Gunicorn application server handling formManagement django app"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid ubuntu
setgid www-data
chdir /home/ubuntu/AARC-ServiceManager/ServerSide/formManagement

exec ve/bin/gunicorn --timeout 300 --workers 3 --bind unix:/home/ubuntu/AARC-ServiceManager/ServerSide/formManagement/formManagement.sock formManagement.wsgi:application

nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
                                worker_connections 768;
                                # multi_accept on;
}

http {

                                ##
                                # Basic Settings
                                ##

                                # set client body size (max http request size) #
                                client_max_body_size 50M;

                                #upping the timeouts to allow time for the DB to return from a long running sproc
                                proxy_connect_timeout 300s;
                                proxy_read_timeout 300s;

                                sendfile on;
                                tcp_nopush on;
                                tcp_nodelay on;
                                keepalive_timeout 65;
                                types_hash_max_size 2048;
                                # server_tokens off;

                                # server_names_hash_bucket_size 64;
                                # server_name_in_redirect off;

                                include /etc/nginx/mime.types;
                                default_type application/octet-stream;

                                ##
                                # Logging Settings
                                ##

                                access_log /var/log/nginx/access.log;
                                error_log /var/log/nginx/error.log;

                                ##
                                # Gzip Settings
                                ##

                                gzip on;
                                gzip_disable "msie6";


                                include /etc/nginx/conf.d/*.conf;
                                include /etc/nginx/sites-enabled/*;
}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
aero
  • 1,654
  • 1
  • 21
  • 31
  • A gateway timeout gives a 504 Gateway Timeout. 502 Bad Gateway means the gateway can't be reached at all. – knbk Dec 22 '16 at 19:06
  • 1
    @knbk, you're right knbk. Nginx is giving me a 502 because gunicorn (an "upstream process") is timing out, not Nginix itself. 502 could mean it can't be reached, but when my query is less than 30 seconds, gunicorn is reached and responds just fine. – aero Dec 22 '16 at 20:28
  • I have exaclty the same problem here but I'm using httpd as proxy. – Arian Pasquali Apr 20 '18 at 16:19
  • 1
    I have exactly the same problem here, but I m using httpd as proxy to gunicorn. I have been trying to fix this for a couple of hours and nothing. All information and fixes I find is for nginx though. httpd server gives me 502 after 5 seconds. I have tried : TimeOut 30000 KeepAlive On KeepAliveTimeout 30000 RequestReadTimeout header=30 body=120 ProxyTimeout 30000 but nothing seams to work. I m starting to think it is somewhere else. – Arian Pasquali Apr 20 '18 at 16:20
  • 1
    @ArianPasquali Hey Arian, I posted my answer to this thread, but it got deleted. I have a similar answer to a similar question you can see here: https://stackoverflow.com/questions/41271682/nginx-502-bad-gateway-django-gunicorn-when-running-mysql-reports-stored-p/41292030#41292030: I hope this works for you. Good luck. – aero Apr 20 '18 at 20:26

0 Answers0