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
Better-scroll scrolling principle As a parent con...
Table of contents Preface Query usage scenario ca...
Recently I want to use goaccess to analyze nginx ...
In the course of work, you will encounter many ca...
There are two ways to expose container ports in d...
First download JDK. Here we use jdk-8u181-linux-x...
I have encountered a problem. When testing the ed...
The solution to forgetting the initial password o...
This article introduces the development environme...
Without further ado, let's take a look at the...
Click here to return to the 123WORDPRESS.COM HTML ...
The CentOS Project, a 100% compatible rebuild of ...
Table of contents Preface How to implement Vuex f...
Recently, I found that after using the docker loa...
Table of contents background question Problem ana...