Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx "location ~ ." vs "location ~* \."

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.

like image 861
The Dude man Avatar asked Jan 21 '17 13:01

The Dude man


People also ask

What is location NGINX?

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.

Where is NGINX location block?

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.

What is the default location for NGINX?

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

What is alias in location?

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 .

How does Nginx choose the best location block for each request?

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:

What are Nginx location directives?

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.

How does Nginx choose the location for a specific Uri?

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:

How does Nginx decide which regular expression location to use?

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.


1 Answers

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.

like image 147
Richard Smith Avatar answered Oct 14 '22 12:10

Richard Smith