Ngnix Static resource access configuration

Source: Internet
Author: User

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

= The beginning indicates an exact match

The beginning of the ^~ indicates that the URI begins with a regular string and is understood to match the URL path. Nginx does not encode the URL, so the request is/STATIC/20%/AA and can be matched by the rule ^~/static//aa (note is a space).

~ starts with a case-sensitive regular match

~* begins with a case-insensitive regular match

/Universal match, any request will match to.

Multiple location configuration in the case of matching order for (resources, not actually validated, try to know, do not adhere to, for reference only):
First match =, second match ^~, followed by regular matching in file order, finally to/Universal match. When a match is successful, stop the match and process the request according to the current matching rule.


Dynamic resource access:

Location =/{
Proxy_pass Http://tomcat:8080/index
}


Static resource access configuration: (URL root path http://127.0.0.1/directory path corresponding to root)

#请求地址是http://127.0.0.1/images/1.jpg, new images directory in e:/nginx/
#location ~* \. (Gif|jpg|jpeg|png|css|js|ico) $ {
# root e:/nginx/;
#}


#请求地址是http://127.0.0.1/images/1.jpg, new images directory in e:/nginx/
Location ^~/images/{
Root e:/nginx/;
}



Reproduced from: http://cppmule.iteye.com/blog/1693593

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.