title: (upstream prematurely closed connection while reading response header from upstream) ..... && 502 bad gateway
body: <p>I am getting this error log in /var/log/nginx. When I run the site I get a 502 bad gateway after exactly 30 seconds of loading up. If i remove some (time extensive) lines of code everything works fine. I edited the nginx config file but I dont think thats the problem.</p>
  <p>I went to: /etc/nginx/sites-available/django and this is the config I have</p>
  <pre class="lang-sh prettyprint-override"><code>upstream app_server {
      server unix:/home/django/gunicorn.socket fail_timeout=0;
       }
  
       server {
            listen 80 default_server;
             listen [::]:80 default_server ipv6only=on;
  
      root /usr/share/nginx/html;
      index index.html index.htm;
  
      client_max_body_size 4G;
      server_name _;
  
      keepalive_timeout 5;
  
      # Your Django project's media files - amend as required
      location /media  {
          alias /home/django/django_project/django_project/media;
      }
  
      # your Django project's static files - amend as required
      location /static {
          alias /home/django/django_project/django_project/static;
      }
  
      # Proxy the static assests for the Django Admin panel
      location /static/admin {
         alias /usr/lib/python2.7/dist- 
       packages/django/contrib/admin/static/admin/;
      }
  
      location / {
              proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
              proxy_set_header Host $host;
              proxy_redirect off;
              proxy_buffering off;
              proxy_read_timeout 110s;
              proxy_send_timeout 110s;
              proxy_pass http://app_server;
     }
  }
  </code></pre>
  <p>I think I need to change the timeout in the gunicorn config file, but I dont know where that is. I could not find it.</p>