Nginx is too greedy with urls

Hi,

I have a case where a redirect for

word-hyphen

should take precendence over a proxy_pass with

word

only

both are inside location {} directives.

location ~ ^/word-hyphen{
return 301 https://bla/one/two/word-hyphen ;
}

location /word{
proxy_pass http://upstream/ ;
}

I just can’t get it to work.

Any ideas?

Best Regards,
Rainer

If you’re from the apache world, nginx configuration if often
counter-intuitive.

Does the following help?

To find location matching a given request, nginx first checks

locations
defined

using the prefix strings (prefix locations). Among them, the location

with
the

longest matching prefix is selected and remembered.

Then regular expressions are checked, in the order of their appearance

in

the configuration file.

The first matching expression stops the search and nginx will use this

location.

If the longest matching prefix location has the ‘^~’ modifier then

regular

expressions are not checked.

Also, using the ‘=’ modifier it is possible to define an exact match

of
URI

and location. If an exact match is found, the search terminates.

Posted at Nginx Forum:
https://forum.nginx.org/read.php?2,266524,266527#msg-266527

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs