我想在 docker 容器中运行 Nginx,它监听 80 端口,当 url 以单词 api
开头时,我希望它通过 proxy_pass 到端口 8080,我有一些 Web 应用程序监听端口8080。在没有 docker 的情况下,这对我来说一直有效,但是有了 docker,我无法让它工作。
我的 nginx.conf 是这样的:
location /{
# serve static page
}
location /api {
proxy_pass http://0.0.0.0:8080;
}
我用 docker run -d -p 80:80 -p 8080: 8080 nginx
运行我的 nginx 容器
我现在的问题是我无法再运行我的 Web 应用程序,因为它无法监听端口 8080,因为该容器已经在监听它。
最佳答案
docker run -d --net host nginx
试试吧! Nginx 容器将共享主机网络 IP 和所有端口
关于docker - Nginx docker 容器代理传递到另一个端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48048695/