2017-06-21 67 views
-1

两天的工作,我仍然坚持。我正在运行单独的nginx和应用程序容器。应用程序容器有一个烧瓶应用程序,在端口8000上运行gunicorn进程。nginx和烧瓶码头集装箱504错误

每次我导航到localhost:8080这是nginx端口80映射到本地主机,我得到一个加载屏幕和一个nginx 504错误。

这是我看到的终端上:enter image description here

泊坞窗,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 

我会提供更多的信息,如果需要得到一些关于我在挣扎的这个问题上的帮助。

+0

你能直接在'localhost:8000'上访问gunicorn服务器吗? –

+0

不,我尝试过没有成功。 –

+0

这是有道理的,我可以访问它与暴露的端口和映射,但我仍然不能。 –

回答

0

好了,后扑我的头三天,我重新从头开始。重建应用程序容器并运行gunicorn。

从那里我可以确定gunicorn进程超时,因为数据库主机名是不正确的。而不是通过我的应用程序返回的错误,失败失败。

我通过链接postgres容器和web容器来解决这个问题。在我的代码中,我能够使用“postgres”(容器的名称)作为postgres主机名。

检查您的外部主机的地址。

0

NGINX响应504指示网关超时,因为NGINX无法连接后端服务器。因此,您可以在proxy_pass目录找到问题。

我想NGINX无法解析web域名,在两个解决方案:

  1. 而不是IP

    位置/ {

    proxy_pass http://<real_ip>:8000; 
    

    }

  2. 使用上游

    上游卷筒纸{

    server <real_ip>; 
    

    }

    位置/ {

    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; 
    

    }