Root&alias file path and index directory configuration in Nginx _nginx

Source: Internet
Author: User

Root&alias File path Configuration
nginx Specify a file path there are two ways to root and alias, the use of this method is summarized, and it is convenient for everyone to respond quickly in the application process. The main difference between Root and alias is how Nginx interprets the URI after location, which causes the request to be mapped to the server file in different ways.
[Root]
Syntax: Root path
Default value: Root HTML
Configuration segments: HTTP, server, location, if
[Alias]
Syntax: Alias path
Configuration segment: Location
Instance:

Location ~ ^/weblogs/{
 root/data/weblogs/www.jb51.net;
 AutoIndex on;
 Auth_basic      "restricted";
 Auth_basic_user_file passwd/weblogs;
}

If the URI of a request is/weblogs/httplogs/www.jb51.net-access.log, the Web server will return the/data/weblogs/www.jb51.net/weblogs/on the server Httplogs/www.jb51.net-access.log's file.
Root is mapped according to the full URI request, which is/path/uri. [
Therefore, the previous request is mapped to Path/weblogs/httplogs/www.jb51.net-access.log.

Location ^~/binapp/{ 
 limit_conn limit 4;
 Limit_rate 200k;
 internal; 
 alias/data/statics/bin/apps/;
}

The alias discards the path configured behind the location and points the directory that is currently matched to the specified directory. If the URI of a request is/binapp/a.jb51.net/favicon, the Web server will return the/DATA/STATICS/BIN/APPS/A.JB51.NET/FAVICON.JGP file on the server.
1. When using alias, you must add "/" after the directory name.
2. Alias can specify any name.
3. Alias when using a regular match, you must capture what you want to match and use it at the specified content.
4. The alias can only be located in a location block.

Index directory Configuration
to simply share files, some people use SVN, some use FTP, but more people use the index function. Apache has a powerful index, and is also the most common, nginx auto_index to achieve a small directory index, and the function is very simple. Let's take a look at our effect chart first.

Nginx Configuration

    Location ~ ^/2589 (/.*)
    {
        autoindex on;//Open
        autoindex_localtime on;//turn on display features
    }

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.