宿主机是Windows,使用vagrant + virtualBox+Ubuntu,在Ubuntu下安装docker,docker中拉取Apache镜像。Windows下浏览器访问网站,会发现网站返回了http://172.17.0.2。
原因是nginx配置有问题,后台服务器返回的本机地址。正确配置:
nginx配置如下:
server { listen 8080; server_name 127.0.0.1:8080; location / { proxy_pass http://172.17.0.2:80; proxy_set_header Host $host:8080; } }
此处的proxy_set_header Host $host 是必须得。
一些Http头部信息不回转发给后台服务器,其中就包括代理服务器的host信息,如果http header没设置,则docker中Apache是获取docker本机IP地址。
所以,要解决这个问题,需要在配置代理的时候,显示告诉代理服务器,需要把代理服务器的Host转发给后台服务。
Comments (0)