nginx 的 location模块中 root 与 alias 区别

###

1.配置方式使用root 与 alias

http {
  ...
  server: {
        location / {
             root /usr/share/nginx/html;
        }
        # root配置文件下载 - 页面404
        location /downloadroot {
            root /etc/nginx/downloadFile;
            autoindex on;
            autoindex_exact_size off;
        }
        # root配置文件下载 - 修改本地文件存放目录,成功下载
        location /downloadchangefiledir {
            root /etc/nginx/downloadFile;
            autoindex on;
            autoindex_exact_size off;
        }
        # alias配置文件下载  - 成功下载
        location /downloadalias {
            alias /etc/nginx/downloadFile;
            autoindex on;
            autoindex_exact_size off;
        }
  }
  ...
}

2.详解 - root/alias区别

1、downloadroot
当配置 root /etc/nginx/downloadFile; 时
访问 http://192.168.2.44/downloadroot/
他找的是:/etc/nginx/downloadFile/downloadroot  
 

2、downloadchangefiledir:
把我的本地存放文件路径改一下:mkdir -p /etc/nginx/downloadFile/downloadchangefiledir && touch /etc/nginx/downloadFile/downloadchangefiledir/2.txt
再访问 http://192.168.2.44/downloadchangefiledir/
他找的是:/etc/nginx/downloadFile/downloadchangefiledir ,此时就可以访问到了。
3、downloadalias
当配置 alias /etc/nginx/downloadFile; 时
请求 http://192.168.2.44/downloadalias/
他找的才是:/etc/nginx/downloadFile

###

原文地址:https://www.cnblogs.com/faithH/p/14505938.html