1

两天的工作,我仍然卡住了。我正在运行单独的 nginx 和应用程序容器。应用程序容器有一个烧瓶应用程序,它在端口 8000 上运行一个 gunicorn 进程。

每次我导航到localhost:8080本地主机上映射到的 nginx 端口 80 时,我都会收到一个加载屏幕和一个 nginx 504 错误。

这是我在终端上看到的:在此处输入图像描述

码头工人-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

如果需要,我会提供更多信息,以便在我正在努力解决的这个问题上获得一些帮助。

4

2 回答 2

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;
    

    }

于 2017-06-21T16:13:03.463 回答
0

好吧,经过三天的猛烈抨击,我从头开始。重建应用程序容器并运行 gunicorn。

从那里我能够确定 gunicorn 进程超时,因为数据库主机名不正确。失败并没有通过我的应用程序返回错误,而是静默了。

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

检查外部主机的地址。

于 2017-06-22T10:17:13.180 回答