Nginx--location Common configuration directives, alias, Root, Proxy_pass

Source: Internet
Author: User
Tags root directory
1, "Alias"--alias configuration, used to access the file system, after matching the URL path to the location configuration, point to the path of "alias" configuration. Such as:
location/test/ 
{ 
    alias/first/second/img/; 
}
That is: Request/test/1.jpg (omitting the protocol and domain name), the file/first/second/img/1.jpg will be returned.
2, "root"--root path configuration, used to access the file system, after matching to the location configuration URL path, point to the "root" configuration path, and attach the location configuration path thereafter. Such as:
location/test/ 
{ 
    root/first/second/img/; 
}
That is: Request/test/1.jpg (omit the protocol and domain name), will return the file/first/second/img/test/1.jpg, compared to alias, using root will append/test/to the root directory.
3, "Proxy_pass"-Reverse proxy configuration, for proxy requests, for the front-end load separation or multiple machines, server load separation scenario, after matching to the location configuration URL path, forwarding the request to the "Proxy_pass" configured URL, Whether the location configuration path will be appended with "/" after the path configured by "Proxy_pass", with "/" is not attached, such as:
location/test/ 
{ 
    proxy_pass http://127.0.0.1:8080/; 
}
That is: Request/test/1.jpg (omit the protocol and domain name), will be the Nginx forwarding request to Http://127.0.0.1:8080/1.jpg (/test/path is not attached).
location/test/ 
{ 
    proxy_pass http://127.0.0.1:8080; 
}
That is: Request/test/1.jpg (omit the protocol and domain name), will be the Nginx forwarding request to http://127.0.0.1:8080/test/1.jpg (additional/test/path).
location/test/ 
{ 
    proxy_pass http://127.0.0.1:8080/img; 
}
That is: Request/test/1.jpg (omit the protocol and domain name), will be the Nginx forwarding request to Http://127.0.0.1:8080/img1.jpg (/test/path is not attached, but the path after the addition of/test/).

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.