In the path of using nginx as a reverse proxy tomcat, session loss may occur. Each time a request is sent, the JESSIONID will change, indicating that the last session is lost and a new session is created. First case: 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 only listens to one port and does not set the path, the problem of session loss generally does not occur. Second case: 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 tomcat folder is specified, not just a port listening, which will cause changes in each request and result in session loss. The third case: 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/ /; //Set the cookie path so that it does not change every time a request occurs. 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, you find that your problem is still not solved. At this time, you are thinking, I have clearly set the cookie path, why doesn’t it work? That’s because you didn’t send the cookie when you requested. The fourth case: 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; //Carry cookie information when sending request 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; } I hope you can find a correct solution on the Internet. This is the end of this article about how to solve the Nginx session loss problem. For more information about Nginx session loss, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: MySQL stored procedure method example of returning multiple values
>>: How to implement Ajax concurrent request control based on JS
Today, let's talk about how to use js to achi...
This article introduces how to install the system...
As we all know, the web pages, websites or web pag...
I recently encountered a problem. The emoticons o...
I encountered a little problem when configuring t...
This article shares the specific code of vue echa...
Preface Currently, the front-end solves cross-dom...
MySQL supports hash and btree indexes. InnoDB and...
Table of contents 1. Keywords 2. Deconstruction 3...
1. Install the express library and generator Open...
In the front-end layout of the form, we often nee...
Prepare the database (MySQL). If you already have...
The docker create command can create a container ...
This article mainly introduces the solution to th...
Preface As you know, Linux supports many file sys...