Nginx-location Configuration

Source: Internet
Author: User

Nginx Location Matching rules:

Syntax rules: location [=|~|~*|^~]/uri/{...}

= Normal character Exact match, this priority is also the highest

~ Wavy line to perform a regular match, case-sensitive

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

^~ represents normal character matching, and if this option matches, matches only that option, and does not match the other options , typically used to match the directory

!~ indicates a case-insensitive match

!~* indicates a case-insensitive match

/generic match, any request will match to, default match


Location-matching Priority:

= Exact Match priority, if exact match is found, Nginx stops searching for other matches

^~ Next Match

The second is a regular match in the Order of the files, and finally a/generic match. When a match succeeds, the match is stopped and the request is processed according to the current matching rule.



For example:

Nginx configuration file: (omitting the previous general configuration)

Server    {    listen 80;    server_name  127.0.0.1;     #默认匹配     location / {       echo  "/";    }     #精确匹配      location =/ {      echo  "=/";    }      #精确匹配     location =/nginx {       echo  "=/nginx";    }     #以gif结尾的区分大小写      location ~ \.gif$ {      echo  "GIF";     }     #以gif结尾的不区分大小写     location ~* \.gif$ {       echo  "GIF";    }     #匹配/static/Path     location ^~ /static/ {      echo  "Static";     }     access_log logs/tomcat1_access.log;    }

Test:

# Curl 192.168.78.131=/# Curl 192.168.78.131/nginx=/nginx# Curl 192.168.78.131/123.gifgif# curl 192.168.78.131/123. gifgif# Curl 192.168.78.131/static/123.gifstatic



This article is from the "Baiyubao blog" blog, make sure to keep this source http://baiyubao.blog.51cto.com/2845008/1759223

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.