Solve the problem of cookie loss when nginx uses proxy_pass reverse proxy

1. If it is only host and port conversion, the cookie will not be lost. For example:
    location /project {         proxy_pass http://127.0.0.1:8080/project;

    }


When accessing http://127.0.0.1/project through a browser, there is a jsessionid in the cookie of the browser. When visiting again, the browser will send the current cookie.


2. If the path also changes, you need to set the path conversion of the cookie. The configuration of nginx.conf is as follows:
    location /proxy_path {         proxy_pass http://127.0.0.1:8080/project;

    }


When accessing http://127.0.0.1/proxy_path through a browser, there is no jsessionid in the browser cookie. When you visit again, the background will of course not be able to get the cookie.

Read the documentation in detail: http://nginx.org/en/docs/http/ngx_http_proxy_module.html?&_ga=1.161910972.1696054694.1422417685#proxy_cookie_path


Add path conversion: proxy_cookie_path /project /proxy_path;

Then you can output the project cookie to proxy_path. The correct configuration is:


    location /proxy_path {
        proxy_pass   http://127.0.0.1:8080/project;
        proxy_cookie_path  /project /proxy_path;
    }

Guess you like

Origin blog.csdn.net/we_shell/article/details/45153885