我有两台服务器,其中一台名为test.example.com
,另一台由以下域解析:www.example.com
和example.com
。我正在尝试将Nginx设置为还实现URL屏蔽的反向代理。基本上,我需要反向代理位于两个服务器和所有三个域的前面才能解析为代理。
当用户尝试访问test.example.com时,我希望加载在www.example.com
和example.com
上托管的网页,而当用户访问URL时,URL保持为test.example.com,反之亦然www.example.com
或example.com
以在test.example.com
上显示网站,并且网址应保持不变。
我执行的步骤:
会发生什么情况,当我输入网站加载的第二个virtualhost(nginx中的服务器)但没有CSS时。
server {
listen 80;
server_name www.example.com example.com;
location / {
proxy_pass https://ip-address-of-the-test.example.com-server/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
server {
listen 80;
server_name test.example.com;
location / {
proxy_pass https://ip-address-of-the-www.example.com-server/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
}
如何获得想要的结果?