Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nginx ignoring location with hyphens

Tags:

nginx

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!

like image 339
p1r0 Avatar asked Jul 14 '12 16:07

p1r0


People also ask

How does Nginx match location?

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.

Does nginx config order matter?

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.

What does Try_files do in nginx?

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.

What does tilde mean in nginx?

~ 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.


1 Answers

try

location ^~ "/user-profile" {
proxy_pass http://remotesites;
}
like image 131
user2832323 Avatar answered Sep 28 '22 01:09

user2832323