: This article mainly introduces how to solve the problem of session loss from proxy_pass to tomcat in nginx. if you are interested in PHP tutorials, refer to it. Introduction
I have always used nginx1.5.7 as the web server and proxy server. it has always been an application that corresponds to one Tomcat, that is, one port, and only one domain name.
Today, Tomcat on the server is integrated. five applications share one Tomcat.
The first problem occurred when a user enters the background. the user information cannot be found!
After debugging, it was found that the request was changed to multiple requests, and the session was inconsistent. it felt like another browser was accessing the request. The conclusion was that the session was definitely lost!
Cause
After careful analysis, we can conclude that the problem lies in the Nginx configuration!
server_name www.weixin4j.org;charset utf-8;root /opt/apache-tomcat-7.0.53/webapps/weixin4j/;location / { proxy_pass http://127.0.0.1:8180/weixin4j/; proxy_set_header Host $host; proxy_set_header X-Real-IP$remote_addr; proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for;}
This configuration will cause the cookie storage location to be not based on "/", so the session will be created again during the second access, so the information in the session is lost.
Solution
Modify the cookie storage path
server_name www.weixin4j.org;charset utf-8;root /opt/apache-tomcat-7.0.53/webapps/weixin4j/;location / { proxy_pass http://127.0.0.1:8180/weixin4j/; proxy_set_header Host $host; proxy_set_header X-Real-IP$remote_addr; proxy_set_header X-Forwarded-For$proxy_add_x_forwarded_for; add_header From www.weixin4j.org; proxy_cookie_path /weixin4j//; proxy_set_header Cookie $http_cookie;}
Restart the service and test it!
Pass!
The above describes how to solve the problem of session loss from proxy_pass to tomcat in nginx, including some content, and hope to help friends who are interested in PHP tutorials.