用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