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!
To find a location match for an URI, NGINX first scans the locations that is defined using the prefix strings (without regular expression). Thereafter, the location with regular expressions are checked in order of their declaration in the configuration file.
Yes, it does and totally depends on different directives specified within the different context supported by Nginx. In layman's term, nginx keeps a stack of things to do and applies certain algorithms respectively with best match in mind.
The try_files directive exists for an amazing reason: It tries files in a specific order. NGINX can first try to serve the static content, and if it can't, it moves on. This means PHP doesn't get involved at all.
~ Tilde means that this location will be interpreted as a case-sensitive RE match. ~* Tilde followed by an asterisk modifier means that the location will be processed as a case-insensitive RE match.
try
location ^~ "/user-profile" {
proxy_pass http://remotesites;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With