This article to you to share the content is about Nginx location configuration introduction (code), the content is very detailed, the need for friends can refer to, hope can help you.
Location is based on the URI to the different positioning, location can be different parts of the site, to different processing methods,
The syntax for location:
Location [=|~|~*|^~] Patt {}//in parentheses is modifier, can not write any parameters, this is called a general match, can also write parameters
therefore , large types can be divided into three kinds:
Location = Patt {} [ exact match ]
Location patt{} [ normal match ]
Location ~ patt{} [ regular match ]
Let's take a look at a picture to see the priority of the match:
Location hit process:
1. Advanced precision matching, if hit immediately return results and end the process of parsing;
2. Exact match misses to determine the normal match, if hit multiple will record "the longest" hit results, but will not end the parsing;
3. Continue to judge the regular match, match the regular expression according to the rule regular match set, if there are more than one regular match from top to bottom, once the match succeeds one will return the result immediately and end the parsing.
PS: The pre-and post-order of the normal match is irrelevant, because the record is the longest result, and the regular match is the so-called, because it is to match from top to bottom, this need to pay attention to!!!
server { listen; server_name localhost; Location =/text.html {#精准匹配, browser input IP address/text.html, navigate to server/var/www/html/text.html file root/var/www/html; Index text.html; } Location/{#普通匹配, browser input IP address, navigate to server/usr/local/nginx/html/default.html file root html; Index default.html; } Location ~ Image {#正则匹配, browser input ip/image. Address will be hit and positioned to/var/www/image/index.html root/var/www/image; Index index.html; } }
Related recommendations:
How does Nginx load balancer be configured? How to configure Nginx load balancer
How does PHP implement load balancing? PHP Implementation Load Balancer instance (code)