Configuration introduction of Nginx location (code)

Source: Internet
Author: User
This article to you to share the content is about Nginx location configuration introduction (code), the content is very detailed, the need for friends can refer to, hope can help you.

Location is based on the URI to the different positioning, location can be different parts of the site, to different processing methods,

The syntax for location:

Location [=|~|~*|^~] Patt {}//in parentheses is modifier, can not write any parameters, this is called a general match, can also write parameters

therefore , large types can be divided into three kinds:

Location = Patt {} [ exact match ]

Location patt{} [ normal match ]

Location ~ patt{} [ regular match ]

Let's take a look at a picture to see the priority of the match:

Location hit process:

1. Advanced precision matching, if hit immediately return results and end the process of parsing;

2. Exact match misses to determine the normal match, if hit multiple will record "the longest" hit results, but will not end the parsing;

3. Continue to judge the regular match, match the regular expression according to the rule regular match set, if there are more than one regular match from top to bottom, once the match succeeds one will return the result immediately and end the parsing.

PS: The pre-and post-order of the normal match is irrelevant, because the record is the longest result, and the regular match is the so-called, because it is to match from top to bottom, this need to pay attention to!!!

server {        listen;         server_name localhost;         Location =/text.html {#精准匹配, browser input IP address/text.html, navigate to server/var/www/html/text.html file            root/var/www/html;               Index text.html;        }        Location/{#普通匹配, browser input IP address, navigate to server/usr/local/nginx/html/default.html file            root html;               Index default.html;        } Location ~ Image {#正则匹配, browser input ip/image.      Address will be hit and positioned to/var/www/image/index.html root/var/www/image;    Index index.html; }    }

Related recommendations:

How does Nginx load balancer be configured? How to configure Nginx load balancer

How does PHP implement load balancing? PHP Implementation Load Balancer instance (code)

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.