Nginx docker容器不接受并从容器中提供烧瓶

时间:2017-06-20 16:12:46

标签: python nginx docker docker-compose

所以我在过去几个小时里一直在讨论这个问题,而且我有一个 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 

这是我终端的最新消息:terminal shot

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

1 个答案:

答案 0 :(得分:1)

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

 ports:
  - "8880:80"

或让nginx侦听端口8080