2017-05-15 74 views
0

所有鏈接我反向代理的IP限制的頁面是這樣的:重寫逆向代理

server { 
    server_name mypage.com; 
    listen 80 ; 

    location/{ 
     proxy_pass https://sandbox.otherpage.com/; 
     proxy_bind $server_addr; 
    } 
} 

這工作不錯,但在網頁上的所有鏈接(包括AJAX調用)鏈接https://sandbox.otherpage.com/

我不確定我做錯了什麼,或者我正在代理的其他Web應用程序鏈接到絕對頁面。

我該如何重寫這些鏈接?

回答

1

您可以使用sub filters做你想做什麼

location/{ 
    proxy_pass https://sandbox.otherpage.com/; 
    proxy_bind $server_addr; 
    sub_filter "https://sandbox.otherpage.com/" "https://myserver.com/"; 
    sub_filter_once off; 
    sub_filter_types *; 
} 

可以擺脫sub_filter_types的,如果你只需要匹配的html文件。您也可以添加proxy_set_header Accept-Encoding ""

+0

這是驚人的,但可惜它不起作用。即使在網站上替換簡單的字符串也不起作用。 我的nginx配置了強制的'--with-http_sub_module'。我通過'nginx -V'檢查過它。 你有一個想法可能是什麼原因? – Hedge

+0

我能夠自己解決問題。我不得不添加以下選項:'proxy_set_header接受編碼「」'和'sub_filter_types *' – Hedge

+0

這取決於您需要做哪些替換的文件,我假設只有html,會更新答案 –