title: nginx forward to localhost 502 Bad Gateway
body: <p>I have nginx as proxy to api (localhost:5000). I want forward request on port 555 to localhost 5000. I'm using docker for nginx and api application.</p>
  
  <p>docker-compose.yml</p>
  
  <pre><code>version: '3.6'
  
  services:
    app:
      build:
        context:  ./server/xxx.Api
        dockerfile: Dockerfile
      network_mode: host
  
    proxy:
      build:
        context:  ./server/nginx
        dockerfile: Dockerfile
      ports:
        - "555:555"
  </code></pre>
  
  <p>nginx.conf:</p>
  
  <pre><code>server {
    listen 555;
    server_name localhost;
    location / {
      proxy_pass http://127.0.0.1:5000;
      proxy_set_header    Host             $host;
      proxy_set_header    X-Real-IP        $remote_addr;
      proxy_set_header    X-Forwarded-For  $proxy_add_x_forwarded_for;
      proxy_set_header    X-Client-Verify  SUCCESS;
      proxy_set_header    X-Client-DN      $ssl_client_s_dn;
      proxy_set_header    X-SSL-Subject    $ssl_client_s_dn;
      proxy_set_header    X-SSL-Issuer     $ssl_client_i_dn;
      proxy_read_timeout 1800;
      proxy_connect_timeout 1800;
    }
  }
  </code></pre>
  
  <p>But instead of application in 5000 port I'm having 502 Bad Gateway from nginx. Application is also in docker.</p>
  
  <p>If I forward request to another website </p>
  
  <pre><code>proxy_pass http://reddit.com;
  </code></pre>
  
  <p>everything works. What is wrong here?</p>