Turn: https://www.jianshu.com/p/9fd2ea5b7d12
Location regular expression writing example:
1. Equal sign (=)
Perform the operation only if the rule matches exactly
location = /index {
[ configuration A ]
}
URL for a http://{domain_name}/index
while, will perform configuration operations.
2. The tilde (~)
Means performing regular matching, 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. Tilde and asterisk (~ *)
Means perform regular matching, but not case sensitive
location ~* /\.(jpg|jpeg|gif) {
[ configuration C ]
}
The jpg、jpeg、gif
configuration takes effect when all urls are matched .
4. Off character and tilde (^ ~)
Indicates common character matching, prefix matching is valid, and the configuration takes effect
location ^~ /images/ {
[ cofigurations D ]
}
URL is http://{domain_name}/images/1.gif
, the configuration takes effect.
5.@
Define a location to handle internal redirection
location @error {
proxy_pass http://error;
}
The effective priority of each character
= > ^ ~ > ~ / ~ *
When there are multiple regular matches in (~ / ~ *) , select the configuration with the longest regular expression to execute.