title: Docker nginx cannot reverse proxy within default network
body: <p>I'm having problems with nginx reverse proxying as a docker container. My question is about how to correctly proxy pass nginx in a default docker network?</p>
  
  <p>Here's my docker-compose.yml (unnecessary details omitted for brevity)</p>
  
  <pre><code>    version: '3'
  
      networks:
        nginx_default:
            external: true
  
      services:
        db:
          image: postgres:10.2
          ports:
            - "5432:5432"
          environment: ...
  
        postgrest:
          image: postgrest/postgrest
          ports:
            - "3000:3000"
          environment: ...
  
        nginx:
          restart: always
          image: nginx:latest
          ports:
            - "8080:80"
          volumes:
            - ./nginx/nginx.conf:/etc/nginx/sites-enabled/ruler
          command: [nginx-debug, '-g', 'daemon off;']
  
        webapp:
          build:
            context: "./"
            dockerfile: Dockerfile.dev
          volumes: ...
          ports:
            - "3001:3001"
          environment: ...
  </code></pre>
  
  <p>Here's my nginx.conf</p>
  
  <pre><code>    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
      }
  
      server {
        listen 80;
        server_name _;
  
        gzip on;
        gzip_proxied any;
        gzip_types text/plain text/xml text/css application/x-javascript;
        gzip_vary on;
        gzip_disable "MSIE [1-6]\.(?!.*SV1)";
  
        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log warn;
  
        location / {
          try_files $uri @node;
        }
  
        location /api/ {
          try_files $uri @postgrest;
        }
  
        location @node {
          proxy_pass http://webapp:3001;
          proxy_redirect off;
          proxy_http_version 1.1;
  
          proxy_set_header Upgrade $http_upgrade;
          proxy_set_header Connection 'upgrade';
          proxy_cache_bypass $http_upgrade;
  
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header Host $host;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Proto $scheme;
  
          proxy_cache_bypass $http_cache_control;
          add_header X-Proxy-Cache $upstream_cache_status;
        }
  
        location @postgrest {
          proxy_pass http://postgrest:3000;
          proxy_http_version 1.1;
  
          default_type application/json;
  
          proxy_set_header  Connection "";
          proxy_hide_header Content-Location;
          add_header Content-Location  /api/$upstream_http_content_location;
        }
      }
  </code></pre>
  
  <p>And my Dockerfile.dev </p>
  
  <pre><code>    FROM node:8.9
  
      WORKDIR /client
  
      CMD npm run dev -- -p 3001
  </code></pre>
  
  <p>When I do <code>$ docker-compose up -d</code> everything starts without an error. After that I can successfully do <code>$ curl http://127.0.0.1:3001/</code> (webapp) and <code>$ curl http://127.0.0.1:3000</code> (postgrest). </p>
  
  <p>But when I try <code>$ curl http://127.0.0.1:8080/</code> (nginx should handle here the proxying) I get default nginx welcome page. Also <code>$ curl http://127.0.0.1:8080/api/</code> is not hitting the API :/</p>
  
  <p>What may be the cause? Using <code>$ docker inspect</code> I see that every container is in the same default network.</p>
  
  <p>Edit: Using <code>$ docker-compose logs</code> seems like the default network is not used at all O_o</p>
  
  <pre><code>    docker-compose logs
      WARNING: Some networks were defined but are not used by any service: nginx_default
      Attaching to ruler_webapp_1, ruler_nginx_1
      webapp_1  | 
      webapp_1  | &gt; ruler@ dev /client
      webapp_1  | &gt; next "-p" "3001"
      webapp_1  | 
      webapp_1  | &gt; Using external babel configuration
      webapp_1  | &gt; Location: "/client/.babelrc"
      webapp_1  |  DONE  Compiled successfully in 1741ms09:04:49
      webapp_1  | 
  </code></pre>