Nginx uses location matching URL for pseudo-static

Source: Internet
Author: User

Basic knowledge
    1. Nginx Location Configuration Syntax

          1. location [ = | ~ | ~* | ^~ ] uri { ... }    2. location @name { ... } 
      1. Location configuration can be configured in two ways

        1.前缀 + uri(字符串/正则表达式)[email protected] + name
      2. Prefix meaning

            =  :精确匹配(必须全部相等)    ~  :大小写敏感    ~* :忽略大小写    ^~ :只需匹配uri部分    @  :内部服务跳转
    2. Location Basics

      1.location is configured in the server block.
      2. Different configurations can be used depending on the URI (configured in the location) to handle various requests.
      The 3.location is sequential and will be processed by the first matching location.

Location Configuration Demo

1. = , Exact match

        location = / {            #规则        }        # 则匹配到 `http://www.example.com/` 这种请求。 

2. ~ , Case sensitive

        location ~ /Example/ {                #规则        }        #请求示例        #http://www.example.com/Example/ [成功] #http://www.example.com/example/ [失败]

3. ~* , Case ignored

    location ~* /Example/ {                #规则    }    # 则会忽略 uri 部分的大小写    #http://www.example.com/Example/ [成功] #http://www.example.com/example/ [成功]

4. ^~ , match only with URI beginning

    location ^~ /img/ {            #规则    }    #以 /img/ 开头的请求,都会匹配上    #http://www.example.com/img/a.jpg [成功] #http://www.example.com/img/b.mp4 [成功]

5. @ , Nginx internal jump

    location /img/ {        error_page 404 @img_err;    }        location @img_err { # 规则 } #以 /img/ 开头的请求,如果链接的状态为 404。则会匹配到 @img_err 这条规则上。
Summarize

The location in Nginx is not as difficult to understand as it is to be feared. Look for more information, try more. You will have a harvest.

Nginx uses location matching URL for pseudo-static

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.