Nginx:重写/ Proxy_Pass而不更改原始URL

时间:2016-10-26 15:56:59

标签: nginx url-redirection

我已经搜索了几个关于此的问题,但没有遇到我的情况。

这就是我需要的:

当有人在线想要从网站购买电脑时,我的客户代理使用以下网址buysomething.acmecorporation.com/computers。但是,这需要重定向到销售它的实际供应商 - 类似于:

computers.world.com - 需要翻译的每个上下文 (例如)printers.world.com

我已成功与供应商合作

     location /computers {
        rewrite ^/(computers.*)$  https://computers.world.com;
        proxy_set_header request_uri $request_uri;
        proxy_pass https://buysomething.acmecorporation.com/computers;
    }

网站正常打开 - 但浏览器上的网址更改为computers.world.com。供应商应该做些什么才能确保持续存在?

或者这是对我的客户(acmecorporation)方面的改变吗?

非常感谢!

1 个答案:

答案 0 :(得分:0)

您将无法通过nginx重定向到维护前网址的外部网站。但是,您可以通过HTML frameset执行类似的操作。

访问buysomething.acmecorporation.com/computers时,您的应用应在下方呈现html(无<html><body>标记):

<frameset rows="100%">
  <frameset cols="100%">
    <frame src="https://computers.world.com" frameborder="0" >
  </frameset>
</frameset> 

这样computers.world.com将在您的网页中加载,网址不会更改。