Reputation: 126
I am having a problem with nginx "location" directive and regular expressions.
I want to have a location match a url that begins with "/user-profile".
The problem is that nginx does not match that, however if I change the config and try with userprofile (i.e. no hyphen) it works like a charm.
I think that there is regexp related problem, but can't get my head around it.
My current config is:
location ^~ /user-profile {
proxy_pass http://remotesites;
}
And I've also tried with:
location ^~ /user\-profile {
proxy_pass http://remotesites;
}
I appreciate any help you can give me.
Thanks!
Upvotes: 11
Views: 5641
Reputation: 3863
One thing to remember if your location is not working as expected in Nginx, as I just spent ages finding out:
location /fred-plus {
root /var/me
}
/fred will be APPENDED to become ... /var/me/fred-plus
but ...
location /fred-plus {
alias /var/me
}
/fred-plus will REPLACED to become ... /var/me
Just spent a fair while sorting this out after coming from Apache land.
I've included the hyphen as it was the red herring that was not the problem in my case.
Upvotes: 0
Reputation: 141
I think what you are looking for is
location ~ ^/user-profile {
proxy_pass http://remotesites;
}
Upvotes: 0
Reputation: 163
try
location ^~ "/user-profile" {
proxy_pass http://remotesites;
}
Upvotes: 5