admin管理员组

文章数量:1312849

I have three different applications running behind a NGINX reverse proxy.

They all have a login GUI, which uses the same authentication API. Authentication is based on cookies.

My problem is now, that the pathes of the cookies are set differently depending on which GUI is used to login.

The authentication API, actually sets the cookie-path to /, but I assume it is the NGINX proxy, which is overwriting that depending on the location.

Is there a way to set the path of the cookies to /, regardless which GUI is used?

This is how my NGINX configuration looks like:

http {
    server {
        listen       80;
        server_name  localhost;

        location = / {
            rewrite / /admin;
        }

        location /admin/ {
            proxy_pass  http://localhost:9001/;
        }

        location /app/ {
            proxy_pass http://localhost:3100/;
        }

        location / {
            proxy_pass  http://localhost:3000/;
        }
    }
}

Edit 1: I have tried to add

proxy_cookie_path ~*^/.* /;

as described here, but it didn't help. The path of the cookie is still /admin or /app

I have three different applications running behind a NGINX reverse proxy.

They all have a login GUI, which uses the same authentication API. Authentication is based on cookies.

My problem is now, that the pathes of the cookies are set differently depending on which GUI is used to login.

The authentication API, actually sets the cookie-path to /, but I assume it is the NGINX proxy, which is overwriting that depending on the location.

Is there a way to set the path of the cookies to /, regardless which GUI is used?

This is how my NGINX configuration looks like:

http {
    server {
        listen       80;
        server_name  localhost;

        location = / {
            rewrite / /admin;
        }

        location /admin/ {
            proxy_pass  http://localhost:9001/;
        }

        location /app/ {
            proxy_pass http://localhost:3100/;
        }

        location / {
            proxy_pass  http://localhost:3000/;
        }
    }
}

Edit 1: I have tried to add

proxy_cookie_path ~*^/.* /;

as described here, but it didn't help. The path of the cookie is still /admin or /app

Share Improve this question edited Mar 14, 2019 at 16:23 Stefan Meier asked Mar 14, 2019 at 13:05 Stefan MeierStefan Meier 1531 gold badge1 silver badge9 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

The directive proxy_cookie_path is for sure the solutions for the described problem.

(I just found out that my cookie wasn't set from the serverside API but on the client side. So the problem wasn't the NGINX config.)

So for the record:

proxy_cookie_path ~*^/.* /;

should do the trick if the cookie is set from serverside. For more information about the directive, see here.

本文标签: javascriptCookie path with NGINX reverse proxyStack Overflow