核心指令root和alias
原创2026/3/5小于 1 分钟
root 示例
客户端请求www.test.com/images/1.jpg,则对应磁盘映射路径/opt/nginx/html/images/images/1.jpg
location /images {
root /opt/nginx/html/images;
}alias 示例
客户端请求www.test.com/images/1.jpg,则对应磁盘映射路径/opt/nginx/html/images/1.jpg
location /images {
alias /opt/nginx/html/images/; //最后面一定要加 "/"
}提示
共同点 : root 和 alias 两者都都是用来指定 URI 和磁盘文件的映射关系;
区别: root 会将定义路径与 URI 叠加;而 alias 只取定义路径;
至此,本章节的学习就到此结束了,如有疑惑,可对接技术客服进行相关咨询。