使用访问二级域名加载一级域名地址,不能访问(X-Frame-Options)

访问二级域名(aa.test.com.cn,bb.test.com.cn)未登录时登陆页是一级域名地址(www.test.com.cn/uaa/login),ie显示“此内容不能显示在一个框架中”,chrome显示空白
这里写图片描述

console报错

Refused to display ‘http://www.test.com.cn/uaa/login’ in a frame because it set ‘X-Frame-Options’ to ‘DENY’.

触发原因:页面的返回头被设置 X-Frame-Options DENY,不能被iframe引用。
这里写图片描述

解决过程:

  1. 由于用了nginx做反向代理,首先想到通过nginx添加、修改响应头中的X-Frame-Options。
    添加:nginx 中设置 add_header
add_header X-Frame-Options SAMEORIGIN

这里写图片描述
header中有两个X-Frame-Options,不能访问

修改:nginx 中设置 proxy_set_header

proxy_set_header X-Frame-Options SAMEORIGIN

未生效
2. 修改登陆地址,aa.test.com.cn访问时登陆地址为aa.test.com.cn/uaa/login,bb.test.com.cn访问时登陆地址为bb.test.com.cn/uaa/login,在nginx中配置aa.test.com.cn/uaa/login、bb.test.com.cn/uaa/login指向同一认证服务器。未测试
3. 修改tomcat配置文件,不发送X-Frame-Options头,但是本项目认证登陆页面不经tomcat,是由认证服务器发送的,认证服务器由oauth2.0搭建,没找到配置header的位置。
4. 页面添加<meta http-equiv=”X-FRAME-OPTIONS” content=”SAMEORIGIN”>
console报错,无法在页面设置X-FRAME-OPTIONS。
5. 在页面代码里添加

<style id="antiClickjack">body{display:none ! important;}</style>
<script>
if (self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
}
</script>

未测试
6. nginx中有个ngx_headers_more模块,主要用于添加、设置和清除输入或者输出http header头的信息。由于安装nginx时未安装ngx_headers_more模块模块,首先安装模块

[root@template ~]# cd /usr/local/nginx-1.12.0
[root@template nginx-1.12.0]# wget https://github.com/openresty/headers-more-nginx-module/archive/v0.29.tar.gz
[root@template nginx-1.12.0]# tar zxvf 0.29.tar.gz
[root@template nginx-1.12.0]# ./configure --add-module=/usr/local/nginx-1.12.0/headers-more-nginx-module-0.29
[root@template nginx-1.12.0]# make
[root@template nginx-1.12.0]# cp /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.bak
[root@template nginx-1.12.0]# cp /usr/local/src/nginx-1.12.0/objs/nginx /usr/local/nginx/sbin/nginx

在nginx.conf中location /uaa/中添加代码

        more_clear_headers "X-Frame-options";

删除header中的X-Frame-options,测试成功

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值