简体   繁体   English

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

[英]Nginx: Rewrite/Proxy_Pass without changing original URL

I have searched through several questions on this but not come across my scenario. 我已经搜索了几个关于此的问题,但没有遇到我的情况。

Here is what I need: 这就是我需要的:

My customer acmecorporation uses the following URL buysomething.acmecorporation.com/computers when someone online wants to buy computers from site. 我的客户acmecorporation使用以下URL buysomething.acmecorporation.com/computers当有人在线想从网站购买电脑。 However, this needs to be redirected to the actual vendor who is selling it - something like: 但是,这需要重定向到销售它的实际供应商 - 类似于:

computers.world.com - every context that acme needs to be translated into (as an example) printers.world.com computers.world.com - 每个需要翻译的上下文(例如)printers.world.com

I have managed to that working with the vendor 我已经设法与供应商合作

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

The site opens up correctly - however the URL on the browser changes to computers.world.com. 该网站正确打开 - 但浏览器上的URL更改为computers.world.com。 What should the vendor be doing to have the acmecorporation persisted? 供应商应采取什么措施才能确保持续存在?

Or is it a change on my customer (acmecorporation) side? 或者这是对我的客户(acmecorporation)方面的改变?

Thanks much ! 非常感谢 !

You won't be able to redirect to an external website maintaining the former url via nginx. 您将无法通过nginx重定向到维护前URL的外部网站。 However you will be able to do something like it through HTML frameset . 但是,您可以通过HTML框架集执行类似的操作。

When buysomething.acmecorporation.com/computers is accessed your application should render the html below (no <html> or <body> tags): 当访问buysomething.acmecorporation.com/computers ,您的应用程序应该呈现下面的html(没有<html><body>标签):

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

That way computers.world.com will be loaded inside your page and the URL will not change. 这样, computers.world.com将被加载到您的页面内,URL将不会更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM