用Nginx解决页面无法被Iframe


location /www.xxx.com {

   proxy_pass http://www.xxx.com/;
   proxy_hide_header "X-Frame-Options";
   proxy_set_header Accept-Encoding "";
   sub_filter <head> '<head><base href="http://www.xxx.com/" />';
}

上面是nginx的配置

 

proxy_hide_header "X-Frame-Options";

去掉response中的X-Frame-Options,让页面可以让Iframe加载

 

sub_filter <head> '<head><base href="http://www.xxx.com/" />';

将页面中的"<head>"字符串替换成<head><base href="http://www.xxx.com/" />,

作用是让该页面以引入的xxx.com的资源别再发给nginx了,直接去http://www.xxx.com/去获取

 

proxy_set_header Accept-Encoding "";

让www.xxx.com那边别以gzip的方式给nginx传页面,该句为sub_filter 服务,gzip压缩的页面sub_filter无法识别和处理


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM