服务器 Gind.cn

服务器问题集锦,包括 Linux(Ubuntu, Centos,Debian等)和Windows Server服务器

Nginx通过代理redirect,重写和保留URL

在Nginx中,我们一直试图redirect一个URL,如下所示: http://example.com/some/path -> http://192.168.1.24 用户仍然可以在浏览器中看到原始url。 一旦用户被redirect,说他们点击链接到/section/index.html ,我们希望这做一个请求,导致redirect http://example.com/some/path/section/index.html -> http://192.168.1.24/section/index.html 并再次保留原来的url。 我们的尝试涉及使用代理和重写规则的各种解决scheme,下面显示了使我们最接近解决scheme的configuration(请注意,这是example.com Web服务器的Web服务器configuration)。 但是,这仍然有两个问题: 它不会正确执行重写,因为Web服务器http://192.168.1.24收到的请求URL包含/some/path ,因此无法提供所需的页面。 一旦提供页面,当您将鼠标hover在链接上时,该URL中将缺less/some/path 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; } } 我们正在寻找一个解决scheme,只涉及到更改example.com上的Web服务器configuration。 我们可以改变192.168.1.24 (也是Nginx)上的configuration,但是我们想要避免这种情况,因为我们需要为通过example.com访问的数百个不同的服务器重复这个设置。