微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐