Skip to content

Latest commit

 

History

History
35 lines (25 loc) · 1.19 KB

alias-vs-root.md

File metadata and controls

35 lines (25 loc) · 1.19 KB

Nginx alias vs root

他们都是 nginx 虚拟目录配置,不同的是他们处理路径的方式。

Introduction

alias

官方文档

Defines a replacement for the specified location.

location 部分会替换 path,所以 final path = alias

root

官方文档

Sets the root directory for requests. A path to the file is constructed by merely adding a URI to the value of the root directive. If a URI has to be modified, the alias directive should be used.

location 部分会添加到 path 上,所以 final path = root + location

Examples

location /img/ {
    alias /var/www/image/;
}
# 访问/img/目录里面的文件时,ningx会自动去/var/www/image/目录找文件
location /img/ {
    root /var/www/image;
}
# 访问/img/目录下的文件时,nginx会去/var/www/image/img/目录下找文件。]

参考资源