请教一下,我用 docker-compose 部署 Flask + Nginx + Docker-compose + gunicorn 应用,本地访问 0.0.0.0:5000 可以访问,访问 0.0.0.0:80 显示 502 bad gate,但 0.0.0.0:80/static/… 静态文件能成功访问,不知道是配置文件哪个地方配错,有没有什么建议?非常感谢
version: '3'
services:
webapp:
build: .
# command: bash ./start_server.sh
# env_file: .env
volumes:
- ./webapp:/iodock/
ports:
- "5000:5000" # web 容器内的 5000 端口映射到主机的 5000 端口
depends_on:
- nginx
nginx:
restart: always
image: nginx:stable
volumes:
- ./webconf/nginx/conf.d/:/etc/nginx/conf.d/
- ./webconf/nginx/log/:/var/log/nginx/
- ./webconf/nginx/cert/:/opt/cert/
- ./webapp/app/static/:/opt/static/
ports:
- "80:80"
- "443:443"
# --------------------------
# Docker file
# --------------------------
FROM python:3.6
# Set system language
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8
# install python requirement
COPY ./webapp/requirements.txt /tmp/requirements.txt
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple --upgrade pip
RUN pip3 install --no-cache-dir gunicorn
RUN pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple -r /tmp/requirements.txt
# Create root folder docker_web_app
COPY ./webapp /docker_web_app/iodock/
WORKDIR /iodock/
# ENV PORT 5000
EXPOSE 5000
CMD ["/usr/local/bin/gunicorn", "-w", "2", "-b", ":5000", "manage:app"]
server {
listen 80;
server_name localhost; # 公网地址
access_log /var/log/nginx/nginx_access.log;
error_log /var/log/nginx/nginx_error.log;
location / {
proxy_pass http://localhost:5000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /static {
alias /opt/static;
proxy_set_header Host $host;
# proxy_cache mycache;
# expires 30d;
}
}
2019/04/21 14:36:18 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "0.0.0.0"
2019/04/21 14:36:18 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "0.0.0.0"
2019/04/21 14:36:19 [error] 7#7: *1 no live upstreams while connecting to upstream, client: 172.18.0.1, server: localhost, request: "GET /favicon.ico HTTP/1.1", upstream: "http://localhost/favicon.ico", host: "0.0.0.0", referrer: "http://0.0.0.0/"
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.