title: Nginx responds with 502 error
body: <p>While trying to deploy my app to Digital ocean I did everything according to this tutorial: <a href="https://www.digitalocean.com/community/articles/how-to-deploy-a-local-django-app-to-a-vps" rel="nofollow">How To Deploy a Local Django App to a VPS</a>.</p>
  
  <p>While Gunicorn is working perfectly and <code>http://95.85.34.87:8001/</code> opens my app, Nginx, however, does not work, <code>http://95.85.34.87</code> or <code>http://95.85.34.87/static</code> causes a 502 error.</p>
  
  <p>Nginx log says, that :</p>
  
  <pre><code>2014/04/19 02:43:52 [error] 896#0: *62 connect() failed (111: Connection refused) while connecting to upstream, client: 78.62.163.9, server: 95.85.34.87, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8001/", host: "95.85.34.87"
  </code></pre>
  
  <p>My nginx configuration file looks like this:</p>
  
  <pre><code>server { 
  listen 80 default_server; 
  listen [::]:80 default_server ipv6only=on; 
  server_name 95.85.34.87;
  
  access_log off;
  
  location /static/ { 
  alias /opt/myenv/static/; 
  }
  
  location / { 
  proxy_pass http://127.0.0.1:8001; 
  proxy_set_header X-Forwarded-Host $server_name; 
  proxy_set_header X-Real-IP $remote_addr; 
  add_header P3P 'CP="ALL DSP COR PSAa PSDa OUR NOR ONL UNI COM NAV"'; 
  }
  </code></pre>
  
  <p>In Django.settings I have <code>ALLOWED_HOSTS</code> set to <code>'[*]'</code></p>
  
  <p>Nginx is listening to port 80:</p>
  
  <pre><code>tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      894/nginx
  
  tcp6       0      0 :::80                   :::*                    LISTEN      894/nginx 
  </code></pre>
  
  <p>I think that the point is that Nginx does not point user to Gunicorn for some reason...</p>
  
  <p><strong>EDIT:</strong> I changed the <code>proxy_pass http://127.0.0.1:8001;</code> line under <code>location /</code> to my servers IP address (instead of loccalhost) and everything worked. I am not sure if it's good decission or not.</p>