title: 504 error with nginx and flask docker containers
body: <p>Two days of work and I'm still stuck. I'm running separate nginx and application containers. The application container has a flask app that runs a gunicorn process on port 8000.</p>
  
  <p>Everytime I nav to <code>localhost:8080</code> which is the nginx port 80 is mapped to on localhost, I get a loading screen and a nginx 504 error.</p>
  
  <p>This is what I see on the terminal:<a href="https://i.stack.imgur.com/LVdwy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LVdwy.png" alt="enter image description here"></a></p>
  
  <p><strong>docker-compose.yml</strong></p>
  
  <pre><code>version: '2'
  
  services:
    web:
      restart: always
      build: ./web_app
      expose:
        - "8000"
      ports:
        - "8000:8000"
      volumes:
        - ./web_app:/data/web
      command: /usr/local/bin/gunicorn web_interface:app -w 4 -t 90 --log-level=info -b :8000 --reload
      depends_on:
        - postgres
  
    nginx:
      restart: always
      build: ./nginx
      ports:
       - "8080:80"
      volumes_from:
        - web
      depends_on:
        - web
  
    postgres:
      restart: always
      image: postgres:latest
      volumes_from:
        - data
      volumes:
        - ./postgres/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
        - ./backups/postgresql:/backup
      expose:
        - "5432"
  
    data:
      restart: always
      image: alpine
      volumes:
        - /var/lib/postgresql
      tty: true
  </code></pre>
  
  <p><strong>nginx.conf</strong></p>
  
  <pre><code>server {
  
      listen 80;
      server_name localhost;
      charset utf-8;
  
      location /static/ {
          alias /data/web/crm/web_interface;
      }
  
      location = /favicon.ico {
          alias /data/web/crm/web_interface/static/favicon.ico;
      }
  
      location / {
          proxy_pass http://web:8000;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      }
  }
  </code></pre>
  
  <p><strong>nginx Dockerfile</strong></p>
  
  <pre><code>FROM nginx:latest
  
  RUN rm /etc/nginx/conf.d/default.conf
  
  COPY ./nginx.conf /etc/nginx/conf.d/nginx.conf
  </code></pre>
  
  <p>I'll provide more info if needed to get some help on this issue that Im struggling on.</p>