The priority of NGINX location in the configuration

Source: Internet
Author: User

Location expression type

~ indicates that a regular match is performed, case-sensitive

~* indicates that a regular match is performed, is case-insensitive

^~ indicates normal character matching. Match with prefix. If the match succeeds, the other location is no longer matched.

= Exact Match of ordinary characters. Which is exactly the same.

@ It defines a named location, used when directed internally, such as Error_page, Try_files

Location-Priority Description

The order of location in Nginx location and configuration is not much related. The type of the positive location expression. Expressions of the same type, long strings will match first.

Here are the instructions by priority:

The equals type (=) has the highest precedence. Once the match succeeds, no other matches are found.

An ^~ type expression. Once the match succeeds, no other matches are found.

The priority of the regular expression type (~ ~*). If more than one location has a regular match, the longest regular expression will be used.

The regular string match type. Match by prefix.

Location Priority Example

The configuration entries are as follows:

Location =/{

# just match the request/

[Configuration A]

}

Location/{

# matches all requests that begin with/.

# But if you have a longer expression of the same type, select a longer expression.

# If there are regular expressions that can match, the regular expression is matched first.

[Configuration B]

}

location/documents/{

# matches all requests that begin with/documents/.

# But if you have a longer expression of the same type, select a longer expression.

# If there are regular expressions that can match, the regular expression is matched first.

[Configuration C]

}

Location ^~/images/{

# matches all expressions beginning with/images/and stops matching lookups if the match succeeds.

# So, even if there is a matching regular expression location, it will not be used

[Configuration D]

}

Location ~* \. (Gif|jpg|jpeg) $ {

# matches all requests ending in GIF jpg jpeg.

# But a request that begins with/images/will use the Configuration D

[Configuration E]

}

Request Matching Sample

/-Configuration A

Configuration B/index.html

/documents/document.html, Configuration C

/images/1.gif, Configuration D

/documents/1.jpg, Configuration E

Note that the above matches are independent of the order defined in the configuration file.

Free pick up Brother Lian IT Education Original Linux Operations Engineer video/Detailed Linux tutorials, details of the website customer service: http://www.lampbrother.net/linux/

or hooking up with Q2430675018.

Welcome to the Linux Communication Group 478068715


The priority of NGINX location in the 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.