title: Nginx proxy_pass to docker container doesn't work
body: <p>I have two identiacal docker containers running on different ports on CentOS7 server. Older version runs on port 81, newer one on port 8080 (82,83 were checked as well).</p>
  
  <p>When I'm trying to proxy second container and change port from 81 to 8080 I receive nginx error message (HTTP/1.1 502 Bad Gateway).</p>
  
  <p><strong>Nginx is not in a container.</strong> I just have it installed on the server.</p>
  
  <p>Here is my proxy_pass setting:</p>
  
  <pre><code>location / {
           proxy_pass http://0.0.0.0:8080/;
          }
  </code></pre>
  
  <p>And some additional information:</p>
  
  <pre><code>nginx -t
  nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
  nginx: configuration file /etc/nginx/nginx.conf test is successful
  </code></pre>
  
  <p>If I try to access containers directly via their ports everything works fine.</p>
  
  <pre><code>curl  0.0.0.0:81
  {"msg":"Phone Masks service"}
  </code></pre>
  
  <pre><code>curl  0.0.0.0:8080
  {"msg":"Phone Masks service"}
  </code></pre>
  
  <p>nginx version: nginx/1.16.1</p>
  
  <p>Docker version 19.03.4, build 9013bf583a</p>
  
  <p>Full server config is pretty standard, I didn't change anything except proxy_pass setting</p>
  
  <pre><code>server {
         listen       80 default_server;
         listen       [::]:80 default_server;
         server_name  _;
         root         /usr/share/nginx/html;
  
         # Load configuration files for the default server block.
         include /etc/nginx/default.d/*.conf;
  
         location / {
          proxy_pass http://0.0.0.0:8080/;
         }
  
         error_page 404 /404.html;
             location = /40x.html {
         }
  
         error_page 500 502 503 504 /50x.html;
             location = /50x.html {
         }
     }
  </code></pre>
  
  <p>The command I use to start the container:</p>
  
  <pre><code>sudo docker run --rm -it -p 8080:8080 -e PORT="8080" api
  </code></pre>
  
  <pre><code>sudo docker ps
  CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS                            NAMES
  47ef127e3e49        api                 "/start.sh"         26 minutes ago      Up 26 minutes       80/tcp, 0.0.0.0:8080-&gt;8080/tcp   infallible_borg
  5d5fe891ba30        api                 "/start.sh"         7 hours ago         Up 7 hours          80/tcp, 0.0.0.0:81-&gt;81/tcp       hopeful_cerf
  </code></pre>