Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx location matches

What is the difference between:

 location = /abc {}

and

 locaton ~ /abc {}
like image 349
user650505 Avatar asked Mar 08 '11 22:03

user650505


People also ask

How does Nginx match location?

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.

What is in Nginx regex?

Nginx Location directive allows routing requests to a particular location in the file system. While Nginx is matching or searching a location block against the requested URL, the location directive tells the Nginx where to search for a specific path by including all files and directories.

Can Nginx location blocks match a URL query string?

nginx location block doesn't match query string at all. So it's impossible. This directive allows different configurations depending on the URI.

What is location in Nginx configuration file?

Every NGINX configuration file will be found in the /etc/nginx/ directory, with the main configuration file located in /etc/nginx/nginx. conf . NGINX configuration options are known as “directives”: these are arranged into groups, known interchangeably as blocks or contexts .


1 Answers

location = /abc {} matches the exact uri /abc

location ~ /abc is a regex match on the uri, meaning any uri containing /abc, you probably want: location ~ ^/abc for the uri begining with /abc instead

like image 117
Martin Redmond Avatar answered Oct 06 '22 22:10

Martin Redmond