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

WBOY
Release: 2023-05-12 12:16:40
forward
3689 people have browsed it

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;
}
Copy after login

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/;
}
Copy after login
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!

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