Nginx location Configuration

Source: Internet
Author: User

Nginx location Configuration Location plays an important role in nginx, processing the request string received by Nginx, such as address orientation, data cache, reply control, proxy forwarding, etc.

Location syntax

Location [=|~|~*|^~] URI {
...
}

The [] section is a match type, which can have no meaning:

(1) = Exact match, the request string must be identical to the URI when the match succeeds

(2) ~ Case-sensitive regular matching

(3) ~* case-insensitive regular match

(4) ^~ Note that this is not a regular match, which means that the URI starts with a normal string,

(5) Null means that the URI starts with a normal string and has the same meaning as the previous one, except that the matching order is different

Match type

(1) Normal match (no [] part, or specify ^~)

(2) exact match (=)

(3) Regular match (~ or ~*)


For example:

Location =/{
#精确匹配/, cannot take any strings after host name
...
}

Location/{
#普通匹配, because all addresses begin with/start, so this rule will match to all requests
...
}

Location ~* \. (Gif|jpg|jpeg) $ {
#正则匹配, this rule matches whether the URI ends in. gif or. jpg or. jpeg, not case-sensitive
...
}

Priority for multiple location

(1) To find the exact match, find and stop the match, execute this location

(2) Verify the common matching rules, whether there is a ^~ start match success, have, stop continuing to match, execute this location, no, note the highest matching the bar

(3) In order to verify the regular matching rules, there is a match, stop the continuation of matching, execute this location, otherwise perform the common matching rules of the highest matching the bar

Nginx location Configuration

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.