nginx location configuration in detail

Directives

Match the specified request uri (uri request does not contain a query string, such as http: // localhost:? 8080 / test id = 10, the request uri is / test)

Grammatical forms

location   [ = | ~ | ~* | ^~ | @]   /uri/     { configuration }

Match mode and order

Matching strings of two kinds: ordinary strings (literal string) and the regular expressions (Regular expression The) , where ~ ~ * and regular expressions, and no other prefixes are used for the common prefix string.

1 , the first common match string, the closest match is temporarily stored;
 2 , then the regular expression matching in declaration order in the configuration file, as long as a regular expression to match, matching is stopped, take the regular expression to match result;
 3 , if all the regular expression match is not a command, the result is stored in 1;
 4 , if an ordinary character string and a regular expression match is not on, the packet 404 nOT FOUND.
location = / uri = beginning for exact prefix match, only exact match to take effect. 
LOCATION    ^ ~ / ~ ^ URI beginning no longer expressed after ordinary regular matching string matching. 
LOCATION    ~ ~ pattern beginning showing a case-sensitive match regular. 
LOCATION    ~ * ~ * pattern beginning indicates regular case-insensitive matching. 
LOCATION    / URI without any modifier, expressed prefix match. 
location    /                        generic matches any unmatched other are matched to the location request. 

Note: The match will be based on regular match order, find the first match of the regular expression will stop the search. Common string matching sequence is ignored, it will choose the most accurate match.

Common Configuration

alias-- configuration alias, to access the file system, the path to the location to the URL matching the configuration, the path to the alias configuration: 

    location    / Test /   { 

            alias     / usr / local / ; 

    }
proxy_pass-- reverse proxy configuration, a proxy request for separating the front and rear end of the load or machines, server load scene separation, after a match to the URL path location configured to forward the request URL amount proxy_pass configuration, whether additional location and configuration path after the path if there is configured proxy_pass " / " related with " / " is not attached, such as: 

    location    / Test /   { 

            proxy_pass HTTP: // 127.0.0.1:8080/; 

    }

Reference links:

https://www.jianshu.com/p/d3fb148cb5eb 

Guess you like

Origin www.cnblogs.com/xuyaowen/p/nginx-location.html