重写反向代理页面上的所有链接 [英] Rewrite all links on reverse proxied page
本文介绍了重写反向代理页面上的所有链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在反向代理到受IP限制的页面,如下所示:
I'm reverse proxying to a IP restricted page like this:
server {
server_name mypage.com;
listen 80 ;
location / {
proxy_pass https://sandbox.otherpage.com/;
proxy_bind $server_addr;
}
}
这很好用,但是页面上的所有链接(包括AJAX调用)都链接到 https://sandbox.otherpage. com/
This works good but all links on the page (including AJAX calls) links to https://sandbox.otherpage.com/
我不确定我是在做错什么,还是在我代理的另一个Web应用程序中指向绝对页面的链接.
I am not sure whether I do something wrong or the the other web application I'm proxying to links to the absolute page.
如何重写这些链接?
推荐答案
您可以使用子过滤器做您想做的事
You can use sub filters to do what you want
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
.
You can get rid of the sub_filter_types
if you only need to match html files.
另外,您可能需要添加proxy_set_header Accept-Encoding ""
.
Also you might need to add proxy_set_header Accept-Encoding ""
.
这篇关于重写反向代理页面上的所有链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文