I am trying to combine these 2 Nginx location definitions into 1
location /v1/login {
proxy_pass http://upstream/v1/login;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_header Authorization;
}
location /v1/logout {
proxy_pass http://upstream/v1/logout;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass_header Authorization;
}
So I figured something like this should do the job
location ^~ /v1/(login|logout) {
rewrite ^/v1/(.*)$ /v1/$1 break;
proxy_pass http://upstream;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
But for the life of me I can't get it to work. What am I doing wrong here? I have tried every possible combination of rewrite regexes.
location
definitions in no particular order was the way to go, so the config has become unmanageable. I've consolidated everything else and it is working, except this particular part./v1/login
(or logout) enough, or do you need all paths starting with it, like/v1/login/something.html
? Also,^~
symbols do not work for regex matching, use just~
for case-sensitive match.