程序员qiao

"Hello word" 即是起点,也是终点。

iframe嵌套其他网站被拒绝

X-Frame-Options: HTTP 响应头是用来给浏览器 指示允许一个页面 可否在<frame><iframe><embed> 或者 <object> 中展现的标记。站点可以通过确保网站没有被嵌入到别人的站点里面,从而避免 点击劫持 攻击。
X-Frame-Options 有三个属性值:

  1. deny
    表示该页面不允许在frame中展示,即便是在相同域名的页面中嵌套也不允许。
  2. sameorigin
    表示该页面可以在相同域名页面的frame中展示。
  3. allow-from uri
    表示该页面可以在指定来源的frame中展示。

nginx配置

  需要添加到 ‘http’, ‘server’ 或者 ‘location’ 的配置项中,个人来讲喜欢配置在‘server’ 中

  正常情况下都是使用SAMEORIGIN参数,允许同域嵌套

  add_header X-Frame-Options SAMEORIGIN;

  允许单个域名iframe嵌套

  add_header X-Frame-Options ALLOW-FROM http://whsir.com/;

  允许多个域名iframe嵌套,注意这里是用逗号分隔

  add_header X-Frame-Options "ALLOW-FROM http://whsir.com/,https://cacti.org.cn/";

nginx示例

复制代码
  server {
    listen 80;
    server_name *.xxxxxxx.xyz;

    location /public/ {
      autoindex on;
      alias /usr/local/nginx/html/web/myblog/node/public/;
    }

    location /webgate/ {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_pass http://127.0.0.1:1314/api/;
    }

    location / {
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      # add_header X-Frame-Options deny;
      # 此处设置X-Frame-Options配置
      add_header X-Frame-Options "ALLOW-FROM  https://xxx2.xxxxxxx.com";
      if ($host ~ ^(xxxx)\.xxxxxxx\.xyz$) {
        proxy_pass http://0.0.0.0:8083;
      }
      if ($host ~ ^(xxxx)\.xxxxxxx\.xyz$) {
        proxy_pass http://0.0.0.0:8081;
      }
      if ($host ~ ^(xxxx)\.xxxxxxx\.xyz$) {
        proxy_pass http://0.0.0.0:8082;
      }
      proxy_pass http://127.0.0.1:1314/;
    }
  }
复制代码

 

声明 本人博客的所有东西,部分源于网络书籍和视频,其他的是个人的理解感悟,经过自己整理撰写成博客。 本人博客均只用于个人学习、复习,不作为商业用途,如有侵权,请联系我修改或删除。 联系邮箱:15121014713@163.com

posted on   程序员qiao  阅读(1663)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· Qt个人项目总结 —— MySQL数据库查询与断言

导航

统计信息

点击右上角即可分享
微信分享提示