nginx root与alias


alias path; 定义指定路径的替换路径,也叫别名路径,文档映射的另一种机制;仅能用于location上下文
location /images/{ root指令:给定的路径对应于location的“/”这个URL
root /data/imgs/ 访问:/images/test.jpg --》 /data/imgs/images/test.jpg
}
location /images { alias指令:给定的路径对应于location的“/url/”这个URL, 注意: /images 后建议不要加 /
alias /data/imgs/ 访问:/images/test.jpg --》 /data/imgs/test.jpg
}
注意:location中使用root指令和alias指令的意义不同
(a) root,给定的路径对应于location中的/uri 左侧的/
(b) alias,给定的路径对应于location中的/uri 的完整路径
(c)使用alias的时候location 的URI后面如果加了斜杠则下面的路径配置必须加斜杠,否则403.




实例:
vim alias.conf server { listen
80; server_name alias.zjol.com.cn; charset utf-8; server_name alias.zjol.com.cn; charset utf-8; location /root { root /data/nginx/html/root; index index.html index.htm; } location /alias { alias /data/nginx/html/alias; index index.html index.htm; } }

tree
.
├── alias
│   └── index.html
└── root
  └── root
    └── index.html

 

posted @ 2022-07-07 16:51  yuanbangchen  阅读(2719)  评论(0编辑  收藏  举报