2

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.

Everytime I nav to localhost:8080 which is the nginx port 80 is mapped to on localhost, I get a loading screen and a nginx 504 error.

This is what I see on the terminal:enter image description here

docker-compose.yml

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

nginx.conf

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;
    }
}

nginx Dockerfile

FROM nginx:latest

RUN rm /etc/nginx/conf.d/default.conf

COPY ./nginx.conf /etc/nginx/conf.d/nginx.conf

I'll provide more info if needed to get some help on this issue that Im struggling on.

Andrew Graham-Yooll
  • 2,148
  • 4
  • 24
  • 49

2 Answers2

0

NGINX response 504 indicate gateway timeout, because of NGINX can not connection the backend server. So, you can locate the issue at proxy_pass directory.

I guess NGINX can not resolve web domain name, There is two solution:

  1. instead of IP

    location / {

    proxy_pass http://<real_ip>:8000;
    

    }

  2. use upstream

    upstream web {

    server <real_ip>;
    

    }

    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;
    

    }

Benjamin Yan
  • 114
  • 5
0

Ok, so after three days of bashing my head, I re-started from the ground up. Rebuilt the app container and ran gunicorn.

From there I was able to determine that the gunicorn process was timing out because the database host name was incorrect. Instead of the an error being returned through my application, the failure went silent.

I fixed this by linking the postgres container and the web container. In my code I was able to use "postgres" (the name of the container) as the postgres host name.

Check the addresses to your external hosts.

Andrew Graham-Yooll
  • 2,148
  • 4
  • 24
  • 49