Home >Backend Development >PHP Tutorial >Nginx location configuration introduction (code)
The content of this article is about the configuration introduction (code) of Nginx location. The content is very detailed. Friends in need can refer to it. I hope it can help you.
location is based on Uri To perform different positioning, location can position different parts of the website to different processing methods. The syntax of
is:
location [=|~|~*|^~] patt { } //The brackets are modifiers. You don’t need to write any parameters. This is called a general match. You can also write parametersTherefore,large types can be divided into three types:
Location = patt {} [Accurate Match]
Location patt{} [Normal matching]
Location ~ patt{} [Regular matching]
Let’s first look at a picture to understand the priority of matching: location Hit process: 1. Advanced precise matching. If there is a hit, the result will be returned immediately and the parsing process ends; 2. Precise matching will determine if there is no hit. Ordinary matching will be recorded if there are multiple hits. The "longest" hits the result, but does not end the parsing; 3. Continue to judge the regular match, and match according to the regular expression set by the regular match setting. If there are multiple regular matches, proceed from top to bottom. Match, once the match is successful, the result will be returned immediately and the parsing will end. ps: The order of ordinary matching does not matter, because the longest result is recorded, while regular matching does matter, because it is Match from top to bottom, this needs attention!!!server { listen 80; server_name localhost; location =/text.html { #精准匹配,浏览器输入IP地址/text.html,定位到服务器/var/www/html/text.html文件 root /var/www/html; index text.html; } location / { #普通匹配,浏览器输入IP地址,定位到服务器/usr/local/nginx/html/default.html文件 root html; index default.html; } location ~ image { #正则匹配,浏览器输入IP/image..地址会被命中,定位到/var/www/image/index.html root /var/www/image; index index.html; } }Related recommendations:
How to configure nginx load balancing? nginx load balancing configuration method
#How does php achieve load balancing? PHP load balancing example (code)
The above is the detailed content of Nginx location configuration introduction (code). For more information, please follow other related articles on the PHP Chinese website!