Full-stack developer
by
To help clarify nginx location priority I will expliain the order in which nginx will try to match a location to a request. I also made the following diagram to help explain how nginx chooses a location.
Remember that order matters:
Nginx will look for exact match locations first. If it finds one, it will stop looking for other locations.
e.g.:
location = /about {
#...
}
Next, nginx will look for locations with a preferential prefix. If it finds one, it will stop looking for other locations.
e.g.:
location ^~ /about {
#...
}
If no exact match or preferential prefix is found, nginx will look for regex match locations.
e.g.:
location ~ ^/about {
#...
}
If none of the above is found, nginx will look for locations with no modifier. So if you have a location with no modifier, it will be the last one to be and will be the one that will be used.
e.g.:
location /about {
#...
}