我已经建立了 Dockerfile
如下所示:
FROM python:2-jessie
ENV DOCKER_MODE=1
EXPOSE 1818
# everything is copied to my_app like uwsgi.ini and app files
COPY . /my_app
WORKDIR /my_app
CMD ["uwsgi", "--ini", "uwsgi.ini"]
它就像一个魅力:
Sun Oct 29 15:17:34 2017 - uWSGI http bound on 127.0.0.1:1818 fd 4
Sun Oct 29 15:17:34 2017 - uwsgi socket 0 bound to TCP address 127.0.0.1:43183 (port auto-assigned) fd 3
Sun Oct 29 15:17:34 2017 - Python version: 2.7.14 (default, Oct 10 2017, 02:49:49) [GCC 4.9.2]
Sun Oct 29 15:17:34 2017 - Python main interpreter initialized at 0x1e347e0
Sun Oct 29 15:17:34 2017 - python threads support enabled
Sun Oct 29 15:17:34 2017 - your server socket listen backlog is limited to 100 connections
Sun Oct 29 15:17:34 2017 - your mercy for graceful operations on workers is 10 seconds
Sun Oct 29 15:17:34 2017 - mapped 1155328 bytes (1128 KB) for 50 cores
Sun Oct 29 15:17:35 2017 - WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x1e347e0 pid: 1 (default app)
Sun Oct 29 15:17:35 2017 - *** uWSGI is running in multiple interpreter mode ***
Sun Oct 29 15:17:35 2017 - spawned uWSGI master process (pid: 1)
Sun Oct 29 15:17:35 2017 - spawned uWSGI worker 1 (pid: 9, cores: 50)
Sun Oct 29 15:17:35 2017 - *** Stats server enabled on 127.0.0.1:11818 fd: 12 ***
Sun Oct 29 15:17:35 2017 - spawned uWSGI http 1 (pid: 10)
当我运行 docker 镜像并分配像
33000
这样的端口时,它正在监听该端口:admin@server:~/application$ sudo netstat -nltp | grep 33000
tcp6 0 0 :::33000 :::* LISTEN 10922/docker-proxy
好像没什么不对!现在我的 nginx 代理在端口 80 上传递如下请求:
proxy_pass http://127.0.0.1:33000;
当我将请求发送到端口
80
, 我得到 502 Bad Gateway Error
.为什么会这样?
最佳答案
UWSGI 绑定(bind)到 127.0.0.1
, 我改成 0.0.0.0
在容器上。并有如下内容:
http-socket=0.0.0.0:1818
关于docker - 为什么通过从容器中暴露 uwsgi 端口,nginx 会收到 502 BAD GATEWAY?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47001925/