cookie 跨域解决方法

1、Nginx 正向和反向代理的区别

正向代理和反向代理的区别:正向代理隐藏真实客户端,反向代理隐藏真实服务端,图示:

2、cookie跨域问题

因为cookie存在跨域问题,其中一个解决方法是,设置Nginx代理服务器,将两个服务器域名统一到一个反向代理服务器。

 upstream www.test.com { 
        server 127.0.0.1:8080 weight=1; 
        server 127.0.0.1:8060 weight=1; 
    }

    server {
        listen       80;
        server_name  www.test.com;
        #charset koi8-r;
        #access_log  logs/host.access.log  main;
        location / {
        proxy_pass   http://www.test.com;
        index  index.html index.htm;
        }
    }

3、解决顶级域名与二级域名之间的cookie跨域问题

#通过设置domain
#顶级域名服务器与二级域名服务器之间哪个设置都能生效
#设置完毕后写回到客户端,用另一个服务器即可访问此Cookie
cookie.setDomain("test.com"); 
原文地址:https://www.cnblogs.com/mengfangui/p/10521594.html