Home > Operation and Maintenance > Nginx > How to configure the root&alias file path and index directory in Nginx

How to configure the root&alias file path and index directory in Nginx

王林
Release: 2023-05-13 09:10:14
forward
1769 people have browsed it

root&alias file path configuration
nginx has two ways to specify the file path, root and alias. The usage differences between the two are summarized below to facilitate quick response during the application process. . The main difference between root and alias is how nginx interprets the uri after location, which causes the two to map requests to server files in different ways.
[root]
Syntax: root path
Default value: root html
Configuration section: http, server, location, if
[alias]
Syntax: alias path
Configuration section: location
Instance:

location ~ ^/weblogs/ {
 root /data/weblogs/www.jb51.net;
 autoindex on;
 auth_basic      "restricted";
 auth_basic_user_file passwd/weblogs;
}
Copy after login

If the uri of a request is /weblogs/httplogs/www.jb51.net-access.log, the web server will return /data/weblogs on the server /www.jb51.net/weblogs/httplogs/www.jb51.net-access.log file.
Root will be mapped based on the complete 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/;
}
Copy after login

alias will discard the path configured after location and point the currently matched directory to the specified directory. If the uri of a request is /binapp/a.jb51.net/favicon, the web server will return the file /data/statics/bin/apps/a.jb51.net/favicon.jgp on the server.
1. When using alias, "/" must be added after the directory name.
2. alias can specify any name.
3. When using regular matching, alias must capture the content to be matched and use it at the specified content.
4. Alias ​​can only be located in the location block.

Index directory configuration
In order to simply share files, some people use svn, some people use ftp, but more people use the index function. Apache's indexing function is powerful, and it is also the most common. The directory index implemented by nginx's auto_index is relatively small, and its function is very simple. Let’s take a look at our renderings first.

How to configure the root&alias file path and index directory in Nginx

nginx configuration

location ~ ^/2589(/.*)
    {
        autoindex on; //开启
        autoindex_localtime on;//开启显示功能
    }
Copy after login

The above is the detailed content of How to configure the root&alias file path and index directory in Nginx. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template