在 Nginx 中,我们一直在尝试重定向 URL,如下所示:
http://example.com/some/path -> http://192.168.1.24
Run Code Online (Sandbox Code Playgroud)
用户仍然可以在浏览器中看到原始 URL。一旦用户被重定向,假设他们点击链接到/section/index.html
,我们希望它发出一个导致重定向的请求
http://example.com/some/path/section/index.html -> http://192.168.1.24/section/index.html
Run Code Online (Sandbox Code Playgroud)
并再次保留原始 URL。
我们的尝试涉及使用代理和重写规则的各种解决方案,下面显示了使我们最接近解决方案的配置(请注意,这是 Web 服务器的 Web 服务器配置example.com
)。但是,这仍然存在两个问题:
http://192.168.1.24
包含/some/path
并因此无法提供所需的页面。提供页面后将鼠标悬停在链接上时,/some/path
URL 中缺少
server {
listen 80;
server_name www.example.com;
location /some/path/ {
proxy_pass http://192.168.1.24;
proxy_redirect http://www.example.com/some/path http://192.168.1.24;
proxy_set_header Host $host;
}
location / {
index index.html;
root /var/www/example.com/htdocs;
}
}
Run Code Online (Sandbox Code Playgroud)我们正在寻找一种仅涉及更改example.com
. 我们可以更改192.168.1.24
(也是 Nginx)上的配置,但是我们想尝试避免这种情况,因为我们需要为数百个通过 代理访问的不同服务器重复此设置example.com
。