周凯,个人博客

  • 前端
  • 嵌入式
  • 工具
  • 后端
  • 随笔
个人记录
  1. 首页
  2. 前端
  3. 正文

使用Iframe嵌入地址,X-Frame-Options 无法访问问题的解决方案

2023年 3月 1日 1009点热度 0人点赞 0条评论

问题

  • 正常部署应用后,将部署应用的地址嵌入到ifame中,页面显示拒绝了连接请求,提示报错如下

  • 请求头中返回的时候携带了 x-frame-options Sameorigin

  • 参考 MDN解释 X-Frame-Options - HTTP | MDN (mozilla.org)

解决

  • 修改当前的请求地址nginx配置,对iframe引入的http://com.ityj.frame/xframe/hello,通过nginx过滤掉X-Frame-Options的配置

    location / {
    #root   html;
    #index  index.html index.htm;
    proxy_pass   http://com.ityj.frame;
    
    proxy_hide_header X-Frame-Options;   # 避免出现多个X-Frame-Options属性
    add_header X-Frame-Options ALLOWALL; # 将之前网页的SAMEORIGIN属性给替换了
    }
    
  • 修改后保存,重新加载nginxnginx -s reload,并重新打开页面或者ctrl + F5刷新

🎯 拓展阅读提示

本文涉及的内容已同步至公众号后台,我会在那里分享更多深度内容和实用技巧

→ 点击关注:一行梦境

公众号二维码
本作品采用 知识共享署名 4.0 国际许可协议 进行许可
标签: 暂无
最后更新:2023年 3月 1日

周凯

这个人很懒,什么都没留下

打赏 点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

COPYRIGHT © 2022-现在 周凯,个人博客. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang

蒙ICP备18004897号