![](/img/trans.png)
[英]how can I rewrite url without changing url in the browser with nginx
[英]With nginx proxy/rewrite can I keep the original URL in the browser's Location field?
使用像proxy-pass
/ rewrite
這樣的nginx.conf
功能,我可以將原始 URL保存在瀏覽器的Location字段中嗎?
我有幾個PlayFramework應用程序在不同的端口(9001,9002,...)上運行,並通過nginx.conf
設置代理轉發。 人們瀏覽他們:
http://domain.name/App1/
http://domain.name/App2/
我的nginx.conf
條目如下所示:
location /App1/ {
proxy_pass http://localhost:9001/;
rewrite ^/App1/(.*) http://domain.name:9001/$1;
}
如果我要求http://domain.name/App1/
,我在瀏覽器的位置字段中看到的是http://domain.name:9001
。 我希望我看到的是http://domain.name/App1/
,也就是說,我希望名稱 App1保留在URI中,而我寧願不公開端口號。
假設App1有一個鏈接/location/ABC
。 當我點擊它時,當我希望看到http://domain.name:9001/location/ABC
時,我會看到http://domain.name/App1/location/ABC
。
我可以用nginx.conf
實現這個目的嗎?
PS我在重寫規則中明確地放了http://domain.name
,因為沒有它我在瀏覽器中得到localhost
,而我的瀏覽器的localhost與服務器的不同。
重寫瀏覽器的問題重定向。
如果您只想從上游安裝多個位置 - 您不需要重寫,只需使用:
location /App1/ {
proxy_pass http://localhost:9001/;
}
但應用程序應使用相對鏈接或帳戶作為其絕對位置。
對於更復雜的url操作,您可以使用break
-rewrites:
location /App1/ {
rewrite ^/App1/(.*) /$1 break;
proxy_pass http://localhost:9001;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.