重写反向代理页面上的所有链接
Rewrite all links on reverse proxied page
我正在反向代理到这样的 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 应用程序。
如何重写这些链接?
你可以使用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 *;
}
如果你只需要匹配 html 个文件,你可以去掉 sub_filter_types
。
您可能还需要添加 proxy_set_header Accept-Encoding ""
.
我正在反向代理到这样的 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 应用程序。
如何重写这些链接?
你可以使用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 *;
}
如果你只需要匹配 html 个文件,你可以去掉 sub_filter_types
。
您可能还需要添加 proxy_set_header Accept-Encoding ""
.