Nginx Location regular expressions
Part excerpt from Nginx official website
Syntax:
location [ = | ~ | ~* | ^~ ] uri { ... }
location@name { ... }
Default:—
Context:server, location
-
location writing regular expressions Example:
1. equal sign (=)
It expresses its full matching rules before performing operations
location = /index {
[ configuration A ] }
URL for a http://{domain_name}/index
while, will perform configuration operations.
2. The tilde (~)
That the implementation of a regular match, but case-sensitive
location ~ /page/\d{1,2} { [ configuration B ] }
URL for the http://{domain_name}/page/1
match ending in the digits when 1-99 configuration to take effect.
3, a tilde and an asterisk (* ~)
That the implementation of a regular match, but not case sensitive
location ~* /\.(jpg|jpeg|gif) { [ configuration C ] }
All matches url to jpg、jpeg、gif
at the end, it takes effect.
4. caret and tilde (~ ^)
Represents ordinary characters match, prefix match a valid, the valid configuration
LOCATION ^ ~ / Images / {
[cofigurations D]
}
the URL is http://{domain_name}/images/1.gif
, the configuration effective.
5.@
Defining a location, for processing the internal redirect
location @error {
proxy_pass http://error; } error_page 404 @error;
Each character effective priority
=> ^ ~> ~ / ~ *
When (~ / ~ *) has a plurality of regular match, select regex configured to perform the longest.