Rewrite all links on reverse proxied page

五迷三道 提交于 2019-12-12 01:48:45

问题


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;
    }
}

This works good but all links on the page (including AJAX calls) links to https://sandbox.otherpage.com/

I am not sure whether I do something wrong or the the other web application I'm proxying to links to the absolute page.

How can I rewrite these links?


回答1:


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 *;
}

You can get rid of the sub_filter_types if you only need to match html files.

Also you might need to add proxy_set_header Accept-Encoding "".



来源:https://stackoverflow.com/questions/43980982/rewrite-all-links-on-reverse-proxied-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!