【发布时间】:2017-04-06 21:07:48
【问题描述】:
我在服务器上运行 2 个容器。它们都是带有默认 nginx 镜像的 docker 容器。
我正在尝试使用 Container1 作为 Container2 的反向代理。
Container1 的 IP 地址为 172.17.0.3
Container2 在 IP 地址172.17.0.4
当我 curl Container1 时,我得到了默认的 Nginx 主页。
我已经编辑了容器 2 的默认主页,因此它只是
<p> HI </p> 由 ip 上的 curl 验证。
在我的服务器 etc/hosts 文件中,我添加了这一行
172.17.0.3 testapp.net
我的 Container1 的/etc/nginx/conf.d/default.conf 是这个
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
#error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
server {
listen 80;
server_name testapp.net;
location / {
proxy_pass http://172.17.0.4
}
}
当我执行curl testapp.net 时,我得到了 Container1 的 nginx(基本的 hello nginx html 文件)的主页,并且没有定向到 Container2。为什么会这样?
【问题讨论】:
-
在尝试之前是否重新加载了 nginx 配置?
-
是的,我确实重新加载了配置
-
你是如何修改hosts文件的?在 docker run 或 build 期间?
-
/etc/hosts 文件在我的服务器上,我在创建 2 个容器后对其进行了修改
标签: nginx reverse-proxy