title: nginx docker container: 502 bad gateway response
body: <p>I've a service listening to 8080 port. This one is not a container.</p>
  <p>Then, I've created a nginx container using official image:</p>
  <pre><code>docker run --name nginx -d -v /root/nginx/conf:/etc/nginx/conf.d -p 443:443 -p 80:80 nginx
  </code></pre>
  <p>After all:</p>
  <pre><code># netstat -tupln | grep 443
  tcp6       0      0 :::443                  :::*                    LISTEN      3482/docker-proxy
  # netstat -tupln | grep 80
  tcp6       0      0 :::80                   :::*                    LISTEN      3489/docker-proxy
  tcp6       0      0 :::8080                 :::*                    LISTEN      1009/java
  </code></pre>
  <p>Nginx configuration is:</p>
  <pre><code>upstream eighty {
      server 127.0.0.1:8080;
  }
  
  server {
      listen 80;
      server_name eighty.domain.com;
  
      location / {
        proxy_pass                        http://eighty;
      }
  }
  </code></pre>
  <p>I've checked I'm able to connect with with this server with <code># curl http://127.0.0.1:8080</code></p>
  <pre><code> &lt;html&gt;&lt;head&gt;&lt;meta http-equiv='refresh'
   content='1;url=/login?from=%2F'/&gt;&lt;script&gt;window.location.replace('/login?from=%2F');&lt;/script&gt;&lt;/head&gt;&lt;body
   style='background-color:white; color:white;'&gt;
   ...
  </code></pre>
  <p>It seems running well, however, when I'm trying to access using my browser, nginx tells bt a 502 bad gateway response.</p>
  <p>I'm figuring out it can be a problem related with the visibility between a open by a non-containerized process and a container. Can I container stablish connection to a port open by other non-container process?</p>
  <p><strong>EDIT</strong></p>
  <p>Logs where <code>upstream { server 127.0.0.1:8080; }</code>:</p>
  <pre><code>2016/07/13 09:06:53 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 62.57.217.25, server: eighty.domain.com, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;http://127.0.0.1:8080/&quot;, host: &quot;eighty.domain.com&quot;
  62.57.217.25 - - [13/Jul/2016:09:06:53 +0000] &quot;GET / HTTP/1.1&quot; 502 173 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0&quot; &quot;-&quot;
  </code></pre>
  <p>Logs where <code>upstream { server 0.0.0.0:8080; }</code>:</p>
  <pre><code>62.57.217.25 - - [13/Jul/2016:09:00:30 +0000] &quot;GET / HTTP/1.1&quot; 502 173 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0&quot; &quot;-&quot; 2016/07/13 09:00:30 [error] 5#5: *1 connect() failed (111: Connection refused) while connecting to upstream, client:
  62.57.217.25, server: eighty.domain.com, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;http://0.0.0.0:8080/&quot;, host: &quot;eighty.domain.com&quot; 2016/07/13 09:00:32 [error] 5#5: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 62.57.217.25, server: eighty.domain.com, request: &quot;GET / HTTP/1.1&quot;, upstream: &quot;http://0.0.0.0:8080/&quot;, host: &quot;eighty.domain.com&quot;
  62.57.217.25 - - [13/Jul/2016:09:00:32 +0000] &quot;GET / HTTP/1.1&quot; 502 173 &quot;-&quot; &quot;Mozilla/5.0 (Windows NT 10.0; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0&quot; &quot;-&quot;
  </code></pre>
  <p>Any ideas?</p>