The exact match of Nginx location detailed

Source: Internet
Author: User

A: Location-detailed precision matching

Location syntax

Location has the meaning of "positioning", depending on the URI for different positioning.

In the configuration of the virtual host, is essential, location can be the different parts of the site, to different processing methods.

For example, how do I invoke the PHP interpreter when I encounter. php? --then you need location.

The syntax of location

Location [=|~|~*|^~] Patt {

}

The brackets can not write any arguments, which is called a generic match at this time

You can also write parameters

Therefore, the large type can be divided into 3 kinds

Location = Patt {} [exact match]

Location patt{} [General match]

Location ~ patt{} [regular match]

How does it work?:

First see if there is an exact match, and if so, stop the matching process.

Location = Patt {

Config A

}

if $uri = = Patt, match successfully, use Configa

Location =/{

root/var/www/html/;

Index index.htm index.html;

}

Location/{

root/usr/local/nginx/html;

Index index.html index.htm;

}

If you access http://xxx.com/

The positioning process is

1: Precision match in "/", get index page to index.htm

2: Visit/index.htm again, this internal jump URI is already "/index.htm",

root directory is/usr/local/nginx/html

3: The end result, visited/usr/local/nginx/html/index.htm


  

The exact match of Nginx location detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.