nginx location Regular

Nginx Location regular expressions

0.3582017.10.12 16:39:46 258 words reading 13256

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、gifat 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.

Guess you like

Origin www.cnblogs.com/python-cat/p/11583374.html