简体   繁体   English

Nginx 代理 URL

[英]Nginx Proxy URLs

I am trying to proxy_pass a dynamic location in nginx.我正在尝试 proxy_pass nginx 中的动态位置。

I have two servers with 1 acting as the main website and the other acting as a search service.我有两台服务器,一台作为主网站,另一台作为搜索服务。

Whilst I can successfully pass the search page and results through to the main server - because the links within the results are relative to the search service - when clicking on the result I am redirected to the second server.虽然我可以成功地将搜索页面和结果传递到主服务器 - 因为结果中的链接与搜索服务相关 - 当单击结果时,我被重定向到第二个服务器。

Essentially what I am trying to do is create a dynamic location with the proxy_pass value also being dynamic, too.基本上我想要做的是创建一个动态位置,proxy_pass 值也是动态的。 Hopefully this will allow be to proxy the search service results, too.希望这也将允许代理搜索服务结果。

As an example I require something like the below.作为一个例子,我需要类似下面的东西。 The dynamic values would be the latter 3 location, id and listing elements.动态值将是后 3 个位置、id 和列表元素。

location /property/location/id/listing {
       proxy_pass sub2.website.com/property/location/id/listing
}

Whilst I have created and suggested the location value - this actually doesn't exist on the 'main website' server by default.虽然我已经创建并建议了位置值 - 默认情况下,这实际上并不存在于“主网站”服务器上。

You could try this.你可以试试这个。

location /property/ {
       proxy_pass sub2.website.com/property/
}

as you want location, id, listing to be dynamic因为您希望位置、ID、列表是动态的

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

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