Home  >  Article  >  Operation and Maintenance  >  What is the difference between the root and alias directives in Nginx configuration?

What is the difference between the root and alias directives in Nginx configuration?

WBOY
WBOYforward
2023-05-12 12:16:403626browse

Both root and alias can be defined in the location module, and are used to specify the real path of the requested resource, such as:

location /i/ {
  root /data/w3;
}

Request http://foofish.net/i/top. gif This address, then the corresponding real resource in the server is /data/w3/i/top.gifFile

Note: True The path is the value specified by root plus the value specified by location.

What is the difference between the root and alias directives in Nginx configuration?

And alias is just like its name. The path specified by alias is the alias of location. No matter how the value of location is written, the real path of the resource is the path specified by alias. , for example:

location /i/ {
  alias /data/w3/;
}

When the same request is made to

http://foofish.net/i/top.gif, the resource path searched on the server is: /data/ w3/top.gif

What is the difference between the root and alias directives in Nginx configuration?

Other differences:

1. alias can only be used in location, while root Can exist in server, http and location.


2. alias must be ended with "/", otherwise the file will not be found, and root is optional for "/".


The above is the detailed content of What is the difference between the root and alias directives in Nginx configuration?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete