node.js - 同一域名下不同端口cookie共享问题
巴扎黑
巴扎黑 2017-04-17 15:05:54
0
2
777
巴扎黑
巴扎黑

reply all(2)
Ty80

Now that the front and back ends are separated, the stateless model should be accepted. Try other ways to solve the state saving problem.

For example: User information can be returned in the login interface and processed by the front end.

Peter_Zhu

Use nginx as a reverse proxy and map services on different ports to a unified port to achieve cookie sharing

nginx configuration file example:

server {
    listen       8080;
    server_name  example.com;

    # 将/api路径映射到3000端口
    location ~ ^/(api)/ {
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
    }
    
    # 静态资源直接由nginx负责
    location / {
        root       /some/path;
        index      index.html index.htm;
    }
}
After

, access http://example.com:8080/ as a static resource and http://example.com:8080/api/* as an interface

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template