Is there a difference between the 3 following directives?
location ~* \.(png)$ {
expires max;
log_not_found off;
}
location ~ \.(png)$ {
expires max;
log_not_found off;
}
location ~ .(png)$ {
expires max;
log_not_found off;
}
Thank you in advance for having taken the time thus far.
The location directive within NGINX server block allows to route request to correct location within the file system. The directive is used to tell NGINX where to look for a resource by including files and folders while matching a location block against an URL.
NGINX location directive syntax The NGINX location block can be placed inside a server block or inside another location block with some restrictions. The syntax for constructing a location block is: location [modifier] [URI] { ... ... } The modifier in the location block is optional.
By default the file is named nginx. conf and for NGINX Plus is placed in the /etc/nginx directory. (For NGINX Open Source , the location depends on the package system used to install NGINX and the operating system. It is typically one of /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.)
alias is used to replace the location part path (LPP) in the request path, while the root is used to be prepended to the request path. They are two ways to map the request path to the final file path. alias could only be used in location block, and it will override the outside root .
For each request, Nginx goes through a process to choose the best location block that will be used to serve that request. Nginx does this by comparing the request URI against each location block that has be setup in the configuration. To achieve this, the following process is used:
Nginx Location Directive Explained. Nginx location directives are essential when working with Nginx. They can be located within server blocks or other location blocks. This article will help explain how location directives are used to process the URIs of client requests.
If a = modifier exactly matches the request URI, this specific location block is chosen right away. If no exact (meaning no = modifier) location block is found, Nginx will continue with nonexact prefixes. It starts with the longest matching prefix location for this URI, with the following approach:
As soon as the longest matching prefix location is chosen and stored, Nginx continues to evaluate the case-sensitive and insensitive regular expression locations. The first regular expression location that fits the URI is selected right away to process the request.
These are three forms of regular expression location block. See this document for details.
The ~*
operator makes the test case insensitive.
The .
character has a special meaning in a regular expression: matching any single character (much like ?
does in shell globs).
The \.
sequence (an escaped dot) matches a literal dot character. This means the third example is probably not what you want (assuming you are attempting to match URIs ending with .png
).
See this document for more on regular expressions.
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