Nginx Docker容器代理传递到另一个端口 [英] Nginx docker container proxy pass to another port
问题描述
我想在docker容器中运行Nginx,它侦听端口80,并且当URL以单词api
开头时,我希望它通过proxy_pass到达端口8080,并且我有一些Web应用程序侦听端口8080.在没有docker的情况下为我工作,但是在使用docker的情况下,我无法正常工作.
I want to run Nginx in a docker container, it listens to port 80 and I want it to proxy_pass to port 8080 when the url starts with word api
, and I have some web app listening port 8080. This has been working for me without docker, but with docker, I couldn't get it to work.
我的nginx.conf就像:
My nginx.conf is like:
location /{
# serve static page
}
location /api {
proxy_pass http://0.0.0.0:8080;
}
我用docker run -d -p 80:80 -p 8080: 8080 nginx
我的问题是,我现在不能再运行我的Web应用程序,因为它不能监听端口8080,因为该容器已经在监听它.
My problem is now I can no longer run my web app because it can't listen to port 8080 since that container is already listening to it.
推荐答案
docker run -d --net host nginx
尝试一下! Nginx容器将使用IP和所有端口共享主机网络
Try it! Nginx container will share the host network with IP and all ports
这篇关于Nginx Docker容器代理传递到另一个端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!