Solve the session loss problem of Proxy_pass to Tomcat in Nginx

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.