2017-09-02 171 views
-1

我是nginx新手。 我正嘗試使用nginx將頁面(「example.com/randomText/abc」)重定向到頁面(「example.com/abc」)。重寫url,但顯示原始URL + nginx

location ~ ^/(.*/abc){ 

#method 1 
rewrite (.*) /abc break; 

#method 2 
#return 301 http://$host/abc; 

#method 3 
#proxy_pass http://$host/abc/; 
#proxy_set_header Host $host; 
#proxy_set_header X-Rewrite-URL $request_uri; 
} 

方法1和2工作,但它也改變URL爲 「http://example.com/abc」 方法3返回用502錯誤。

回答

0

你需要的是類似下面

location ~ ^/[^/]+/abc { 
    proxy_pass http://$host/abc; 
} 
+0

它給502錯誤 –