Introduction
I've been using nginx1.5.7 as a Web server and a proxy server, and it's always been an application. A tomcat is also a port, and only one domain name is appropriate.
Today, the Tomcat on the server was consolidated, with 5 apps sharing a tomcat.
The first problem is that users, such as entering the background when the exception, unable to find the login user information!
Debugging found that the request has become multiple, and the session is inconsistent, it feels like another browser in the interview, concluded: The session must have been lost!
Reason
After careful analysis, it concludes that the problem is in 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 causes the cookie to be stored in a location other than "/" and then the session is newly created at the second access, so the information in the session is lost.
Solution Solutions
Modifying the storage path of a cookie
server_name www.Weixin4j.Org;charset UTF-8; Root/opt/apache-tomcat-7.0./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 Cookies$http _cookie;}
Restart the service, test!
Pass!
Solve the session loss problem of Proxy_pass to Tomcat in Nginx