【发布时间】:2018-05-18 15:18:51
【问题描述】:
假设我有三个带有 nginx 的 docker 容器。它们暴露的端口分别映射到 8080、8181 和 8282。我想在 8080 上配置服务器,它将 /example01 和 /example02 代理到其他两个应用程序。这是我的配置文件:
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/;
index index.html index.htm;
}
location /example01 {
proxy_pass http://localhost:8181/;
}
location /example02 {
proxy_pass http://localhost:8282/;
}
}
因此,如果我运行容器,每个应用程序都可以访问(http://localhost:8080、http://localhost:8181 和 http://localhost:8282)。
现在,我真的不明白为什么 http://localhost:8080/example01 和 http://localhost:8080/example02 没有正确重定向。相反,我收到 502 bad gateway 错误。是否与我暴露的端口和 VIRTUAL_PORT 有关?
提前致谢。
【问题讨论】:
-
您可以尝试将配置文件分别编辑为
proxy_pass http://localhost:8181/example01;和proxy_pass http://localhost:8282/example02;
标签: docker nginx docker-compose nginx-reverse-proxy