我一直在阅读反向代理,想知道什么时候proxy_set_header Host $host
是适当的proxy_set_header Host $proxy_host
。我做了一些研究本文 https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching它表示在大多数情况下我们将 Host 设置为 $host。那为什么nginx默认是$proxy_host呢?为了帮助我更具体地理解,反向代理配置here https://whatididtodowhatidid.wordpress.com/2014/03/14/subdomains-for-ports-on-same-ubuntu-server-with-nginx-reverse-proxy/(文章底部)如果我们使用 $proxy_host 代替,仍然有效吗?
Thanks
一般来说,不需要明确地做proxy_set_header Host $proxy_host
因为这是默认的。如果您需要通过某种方式调用服务器other比里面的内容proxy_pass
指令,那么你需要通过覆盖proxy_set_header something
.
如果您想代理same主机就像你的一样server_name
指令,那么你将有机会使用proxy_set_header $host
。如果实际应用程序可能托管在另一个端口或某些内部服务器上,则通常会出现这种情况。
server {
listen 80;
server_name site.example.com;
location / {
proxy_set_header Host $host;
proxy_pass http://localhost:8080;
}
}
如果您调用上游的名称不是其实际的 DNS 名称,那么您可能会看到类似以下内容:
# 192.168.2.1 responds to site.example.com, but
# site.example.com doesn't actually resolve to 192.168.2.1
proxy_pass http://192.168.2.1;
proxy_set_header Host site.example.com;
另一种情况可能是“基于名称”的虚拟主机,其中上游有一个有用的 DNS 名称,但您想用另一个名称来调用它。
proxy_pass http://origin.example.com;
proxy_set_header Host site.example.com
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)