在iframe下存储不上cookie,nginx配置iframe和主窗体同源

在非同源的iframe存储不上cookie

需求描述: 公司的系统A需要嵌入公司系统B的页面。 系统A为C#程序,启动在IIS。在系统A中一个页面通过
iframe嵌入系统B的页面,系统B是shiro的安全框架,前后端接口身份验证通过后端在response设置cookie存
储上Jsessionid。 在谷歌浏览器中存在保护机制,当不同源的页面时无法在子页面存储cookie。导致在嵌套页面无
法正常访问接口。

解决方法: 在请求头加入p3p(可自行百度)没有成功。 最后通过测试发现如果是同源的界面则可以存储上cookie。
同源策略(可自行查询 跨域相关知识  简单说就是 http协议 + IP +  端口 + 域名都要相同才可以算是同源)。最
后通过nginx配置转发代理实现同源解决问题。
 //  nginx配置  程序B的配置
 server {
		listen       10000;

		#location ~ ^/login[^.]+  {
		#location ~ ^/[a-z]+/login$  {
		location  ^/(?!(pms|platform))[^/]+/login$  {
			rewrite .* /login/login.html;
		}

		location / {
			add_header Cache-Control no-cache;
			root  D:\pms-hzj\hzx-front-pc;

			index login.html;
		}

		location /pms/teamwork {
			proxy_pass http://192.168.0.191:12002/pms-teamwork;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
		}
	
		location /pms {
			proxy_pass http://192.168.0.191:12001/pms;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
		}
		location /pms/enterbid {
			proxy_pass http://192.168.0.191:12005/pms-enterbid;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
		}
		
		location /pms/tender{
			proxy_pass http://192.168.0.191:12004/pms-tender;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
		}
		
		location /pms/supervise{
			proxy_pass http://192.168.0.191:12006/pms-supervise;
			proxy_http_version 1.1;
			proxy_set_header Upgrade $http_upgrade;
			proxy_set_header Connection "upgrade";
		}

	  #error页面
	  error_page 404 /404.html;
 }
	 

// 程序A的配置
// 程序B的端口为10000, 现在把程序A和程序B都代理到5555端口。 程序A在IIS启动为14725端口, 
//  默认请求都发送到程序A, 然后iframe的src 应该为 IP:5555/hzj 通过hzj标识转发到10000。
// 由于在程序B的页面中引入方式为/js/xxxx.js 所以默认的访问地址会代理到程序A下面,所以进行转发。具体看下面配置
server {
		listen       5555;


		#location ~ ^/login[^.]+  {
		#location ~ ^/[a-z]+/login$  {
		location  ^/(?!(pms|platform))[^/]+/login$  {
			rewrite .* /login/login.html;
		}


		location / {
		   proxy_pass http://127.0.0.1:14725;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
	 

		location /hzj {
		   proxy_pass http://192.168.0.200:10000/;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
			
		location /js {
		   proxy_pass http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
		location /css {
		   proxy_pass http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
		location /images {
		   proxy_pass http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
	 
	 	location /login {
		   proxy_pass http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}

		location /pms {
		   proxy_pass  http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
		location /sys {
		   proxy_pass  http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
		location /teamwork {
		   proxy_pass  http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
		location /enterbid {
		   proxy_pass  http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}

		location /tender {
		   proxy_pass  http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}
		
			location /supervise {
		   proxy_pass  http://192.168.0.200:10000;
		   proxy_http_version 1.1;
		   proxy_set_header Upgrade $http_upgrade;
		   proxy_set_header Connection "upgrade";
		}

		  #error页面
		  error_page 404 /404.html;
	}
	

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值