nginx反向代理可访问多个docker容器
我想在一个主机VM上运行多个docker容器,该主机VM只能通过一个域访问。我想使用请求url来区分容器。 为了实现这一点,我尝试将nginx服务器设置为反向代理,并在侦听端口80的容器中运行它 假设我有两个集装箱在3000和4000港口运行。 路线如下:nginx反向代理可访问多个docker容器,nginx,docker,reverse-proxy,Nginx,Docker,Reverse Proxy,我想在一个主机VM上运行多个docker容器,该主机VM只能通过一个域访问。我想使用请求url来区分容器。 为了实现这一点,我尝试将nginx服务器设置为反向代理,并在侦听端口80的容器中运行它 假设我有两个集装箱在3000和4000港口运行。 路线如下: docker-host.example.com/3000 -> this will access container exposing port 3000 docker-host.example.com/4000 -> this
docker-host.example.com/3000 -> this will access container exposing port 3000
docker-host.example.com/4000 -> this will access container exposing port 4000
问题是,我目前正在尝试为这种反向代理定义静态规则。
无需任何位置即可正常工作:
upstream application {
server <docker container>:3000;
}
server {
listen 80;
location / {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://application/;
}
}
所以请求url是
而不是
我能问你一些建议吗?这种情况可能吗?您可以为每个端口选择一个docker容器,例如:
upstream application {
server <docker container>:3000;
}
server {
listen 80;
location /3000/ {
proxy_pass_header Server;
proxy_set_header Host $http_host;
proxy_redirect off;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Scheme $scheme;
proxy_pass http://application/3000/;
}
}
09:19:20 [error] 5#5: *1 open() "/etc/nginx/html/public/css/fonts.min.css" failed (2: No such file or directory), client: 172.17.0.1, server: , request: "GET /public/css/fonts.min.css HTTP/1.1", host: "localhost:8455", referrer:"http://localhost:8455/3000/"