Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem of Nginx session loss

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly shows you how to solve the problem of Nginx session loss, the content is easy to understand, I hope you can learn, after learning, there will be a harvest, the following let the editor take you to take a look at it.

The problem of session loss may occur in the path of reverse proxy tomcat with nginx. The JESSIONID changes each time the request is sent, indicating that the last formed session is lost, thus creating a new session.

The first situation:

Server {listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; charset utf-8; location / {proxy_redirect off; proxy_pass http://127.0.0.1:8093; proxy_set_header Host $host; proxy_set_header Referer $http_referer Proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} access_log logs/tomcat_access.log;}

Since the current nginx is only listening on a port and does not set the path, there is generally no problem of session loss.

The second situation:

Server {listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; root / opt/tomcat-jhyx/webapps/jhyx/; charset utf-8; location / {proxy_pass http://127.0.0.1:8093/jhyx/; proxy_set_header Host $host; proxy_set_header Referer $http_referer Proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} access_log logs/tomcat_access.log;}

In this case, the folder where the tomcat is specified, which is not just a port listening, will change with each request, resulting in the loss of session.

The third situation:

Server {listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; root / opt/tomcat-jhyx/webapps/jhyx/; charset utf-8; location / {proxy_redirect off; proxy_pass http://127.0.0.1:8093/jhyx/; proxy_cookie_path / jhyx/ /; / sets the cookie path so that each request does not change. Proxy_cookie_path / jhyx /; proxy_set_header Host $host; proxy_set_header Referer $http_referer; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} access_log logs/tomcat_access.log;}

At this time, found that your problem is still unsolved, then you are thinking, I have clearly set the cookie path, why not, that is because you did not send a cookie request.

The fourth situation:

Server {listen 80; server_name www.jiahemdata.com www.jiahemdata.cn; root / opt/tomcat-jhyx/webapps/jhyx/; charset utf-8; location / {proxy_redirect off; proxy_pass http://127.0.0.1:8093/jhyx/; proxy_cookie_path / jhyx/ /; proxy_cookie_path / jhyx/; proxy_set_header Host $host; proxy_set_header Referer $http_referer Proxy_set_header Cookie $http_cookie; / / request is sent with cookie information proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;} access_log logs/tomcat_access.log } the above is about how to solve the problem of Nginx session loss. If you have learned knowledge or skills, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report