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

 

相关文章

Nginx (engine x) 是一个高性能的HTTP和反向代理服务,也是一...
本地项目配置 1 复制 luffy/settings/dev.py为prop.py 修改l...
nginx不仅可以隐藏版本信息,还支持自定义web服务器信息 先看...
一 、此次漏洞分析 1 nginx HTTP/2漏洞 [nginx-announce] ng...
###进入nginx 目录cd /usr/local/nginx###递归显示 2 级目录...
在cmd命令窗口输入下面命令进行查看 tasklist /fi "ima...