如何解决使用nginx做负载均衡的时候,session一致性的问题??

我想要将两个tomcat部署在不同的服务器上,使用nginx做负载均衡,但是当我访问login页面的时候,就会弹出会话过期。

用的什么转发策略?根据 Nginx 文档,免费版需要配置转发策略为 haship_hash
image

参考下英文论坛里的帖子:
https://www.cuba-platform.com/discuss/t/web-page-stuck-on-session-expired/2242
https://www.cuba-platform.com/discuss/t/user-session-log-shows-local-ip-in-cloud/3236/5?u=rabkesov

有个主要的配置是:

    proxy_cookie_path /app/ /;
    proxy_set_header Cookie $http_cookie;

还有proxy_set_header的配置都跟英文论坛上一致了,再试试。

非常感谢您的回复,原本在我的使用场景下(所有人在同一个局域网段中),ip_hash的方式是不生效的,现在我的使用场景变了,可以用ip_hash啦:grinning: