title: 502 Bad Gateway with NGINX, Gunicorn, Django
body: <p>I tried setting up a project with NGINX and Gunicorn using this <a href="https://www.digitalocean.com/community/tutorials/how-to-set-up-django-with-postgres-nginx-and-gunicorn-on-centos-7" rel="nofollow noreferrer">guide</a>. However, I keep getting a 502 Bad Gateway error.</p>
  
  <p>Here is my server conf:</p>
  
  <pre><code>server {
      listen 80;
      server_name nexus-staging.chop.edu;
      access_log /webapps/nexus/logs/nginx/nexus-staging.chop.edu.access.log main;
      error_log /webapps/nexus/logs/nginx/nexus-staging.chop.edu.error.log warn;
  
      location = /favicon.ico { access_log off; log_not_found off; }
      location /static/ {
          root /webapps/nexus/static_cdn;
      }
  
      location / {
          proxy_set_header Host $http_host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
          proxy_pass http://unix:/webapps/nexus/nexus.sock;
      }
  }
  </code></pre>
  
  <p>Here is my gunicorn service file:</p>
  
  <pre><code>[Unit]
  Description=gunicorn daemon
  After=network.target
  
  [Service]
  EnvironmentFile=/etc/sysconfig/nexus
  User=svc_dgdnexus
  Group=dgd_svc
  WorkingDirectory=/webapps/nexus
  ExecStart=/webapps/nexus/pyvenv/bin/gunicorn --workers 4 --bind unix:/webapps/nexus/nexus.sock django_config.wsgi:application --name nexus --access-logfile /webapps/nexus/logs/gunicorn/nexus-staging.chop.edu.access.log --error-logfile /webapps/nexus/logs/gunicorn/nexus-staging.chop.edu.error.log
  
  [Install]
  WantedBy=multi-user.target
  </code></pre>
  
  <p>This is the nginx error:</p>
  
  <pre><code>2017/02/17 22:55:23 [error] 36168#0: *1 upstream prematurely closed connection while reading response header from upstream, client: 10.249.27.89, server: nexus-staging.chop.edu, request: "GET / HTTP/1.1", upstream: "http://unix:/webapps/nexus/nexus.sock:/", host: "nexus-staging.chop.edu"
  </code></pre>
  
  <p>This is the gunicorn error:</p>
  
  <pre><code>[2017-02-17 22:53:59 -0500] [36143] [INFO] Booting worker with pid: 36143
  [2017-02-17 22:53:59 -0500] [36145] [INFO] Booting worker with pid: 36145
  [2017-02-17 22:55:23 -0500] [36137] [CRITICAL] WORKER TIMEOUT (pid:36140)
  [2017-02-18 03:55:23 +0000] [36140] [INFO] Worker exiting (pid: 36140)
  [2017-02-17 22:55:23 -0500] [36202] [INFO] Booting worker with pid: 36202
  </code></pre>