Nginx Solution for cookie loss problem when using Proxy_pass reverse proxy

Source: Internet
Author: User



today, nginx proxy manager when testing the test environment to find that there is a session page in any case can not go, after debugging found that Jsessionid's path and my access to the application of the path is not the same. I visit the application is/xxx/, and Jsessionid's path is/yyy/, this is the root of the problem! So I changed the application Sessioncookiepath, nginx reverse proxy To be blunt is to create a new context.xml file under Meta-inf under the project root path, specifically:


nginx proxy


<?xml version= "1.0" encoding= "UTF-8"?>





<context usehttponly= "true" sessioncookiepath= "/xxx/"/>





in a test environment, successfully passed, that is, as long as two path inconsistency, will reproduce the test environment problems, nginx proxy_pass with joy in the mood test environment test, the result is still not, debugging found Jsessionid path or the original/yyy/, nginx reverse proxy example incredibly did not work.





later, after thinking, modify Tomcat is not, but should modify Nginx, that is, jwilder nginx proxy through Nginx modify Jsessionid path, the experiment was successful. Here are some specific knowledge:nginx reverse proxy docker









1. If only host, port conversion, the cookie will not be lost. For example:     Location/project {
        Proxy_pass   Http://127.0.0.1:8080/project ;
   }


When http://127.0.0.1/project is accessed through a browser, there is a jsessionid in the browser's cookie. When accessed again, the browser sends the current cookie.




2. If the path also changes, you need to set the path conversion of the cookie, NGINX.CONF is configured as follows
    Location/proxy_path {
  & nbsp     Proxy_pass   Http://127.0.0.1:8080/project;
   } When


accesses Http://127.0.0.1/proxy_path through a browser, there is no jsessionid in the browser's cookie. When you visit again, the background is certainly unable to get the cookie.


Plus path conversion: Proxy_cookie_path  /project        /proxy_path
You can output a project's cookie to the Proxy_path. The correct configuration is:


    Location/proxy_path {
        Proxy_pass   http://127.0.0. 1:8080/project;
        Proxy_cookie_path  /project          /proxy_path;
   }

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.