【问题标题】:Nginx docker container not accepting and serving flask from containerNginx docker容器不接受容器中的烧瓶并提供服务
【发布时间】:2017-11-23 07:07:51
【问题描述】:

所以过去几个小时我一直在努力解决这个问题,我得到了一个 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=debug -b 0.0.0.0: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

但是,当我 docker-compose up 然后导航到 localhost:8880 时,我什么也没得到。就像 nginx 服务器不接受通过 localhost 的连接。

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 

这是我终端里的内容:

我一直在密切关注this 教程,但它似乎无法为我创建的 Flask 应用程序提供服务。有什么想法吗?

【问题讨论】:

  • 告诉我是否遗漏了某些部分...您将 8080 暴露到 nginx 容器中,但您的 nginx 通过端口 80 侦听。

标签: python nginx docker docker-compose


【解决方案1】:

尝试更改nginx服务的端口映射如下:

 ports:
  - "8880:80"

或者让 nginx 监听端口8080

【讨论】:

  • 实际上是在第二次检查时,我不确定是不是因为你或@German 的建议,当我导航到 localhost:8080 时,屏幕会加载一段时间,然后返回 504 nginx 错误。所以这是一个积极的方向。
  • @AndrewGraham-Yooll 你能用你当前的配置更新你的问题吗?
  • @CélineAussourd 完成。
  • @AndrewGraham-Yooll 在您的 nginx 配置中,您正在侦听端口 80,因此您应该在 nginx 部分的 docker-compose 中公开端口 80(不是 8080):- "80:80"(而不是 @ 987654326@)
  • @AndrewGraham-Yooll 关于 WORKER TIMEOUT 错误,这是另一个问题。见:stackoverflow.com/questions/10855197/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-11-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-09
相关资源
最近更新 更多