Home > Backend Development > PHP Tutorial > Nginx location configuration introduction (code)

Nginx location configuration introduction (code)

不言
Release: 2023-04-03 12:36:01
Original
2299 people have browsed it

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

##location

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 parameters

Therefore,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;
    }
    }
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template