nginx 指定文件的路径方式有两种:root、alias,两者的区别有:

root:

就是:根、基础的意思,对于请求 url,起到 “叠加” 的效果。例如:当 nginx 某一 location 这样配置,若浏览器请求的地址为:/root-alias/a.html 时,nginx 会返回路径为 /data/root_path/root-alias/a.html 的资源。

  1. location /root-alias {
  2. root /data/root_path;
  3. }

root 还可用在 http、server、if 配置段里。

alias:

就是:别名的意思,对于请求 url,起到“替代”的效果。例如:当 nginx 某一 location 这样配置,若浏览器请求的地址为:/root-alias/a.html 时,nginx 会返回路径为 /data/root_path/a.html 的资源。

  1. location /root-alias {
  2. alias /data/root_path;
  3. }

alias 只能放在 location 配置段里。

参看:

nginx的location、root、alias指令用法和区别
Nginx静态服务配置—-详解root和alias指令