What order do location directives fire in?
Yes, it does and totally depends on different directives specified within the different context supported by Nginx.
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.
The proxy_pass setting makes the Nginx reverse proxy setup work. The proxy_pass is configured in the location section of any virtual host configuration file. To set up an Nginx proxy_pass globally, edit the default file in Nginx's sites-available folder.
In the Nginx configuration file, the default_server option specifies the default server to which a client request with an unknown domain and an empty host field will be forwarded.
From the HTTP core module docs:
Example from the documentation:
location = / { # matches the query / only. [ configuration A ] } location / { # matches any query, since all queries begin with /, but regular # expressions and any longer conventional blocks will be # matched first. [ configuration B ] } location /documents/ { # matches any query beginning with /documents/ and continues searching, # so regular expressions will be checked. This will be matched only if # regular expressions don't find a match. [ configuration C ] } location ^~ /images/ { # matches any query beginning with /images/ and halts searching, # so regular expressions will not be checked. [ configuration D ] } location ~* \.(gif|jpg|jpeg)$ { # matches any request ending in gif, jpg, or jpeg. However, all # requests to the /images/ directory will be handled by # Configuration D. [ configuration E ] }
If it's still confusing, here's a longer explanation.
It fires in this order.
=
(exactly)
location = /path
^~
(forward match)
location ^~ /path
~
(regular expression case sensitive)
location ~ /path/
~*
(regular expression case insensitive)
location ~* .(jpg|png|bmp)
/
location /path
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