nginx中的root和alias的区别

alias

在E:\\test\\目录下创建一个index.html文件

在nginx.conf文件配置alias,路径填写为绝对路径,但是要注意,这里结尾是文件夹的名字

然后下面的/aa/ 是随便起的名字,也不是文件夹的名字,在浏览器访问的使用的

在浏览器使用 http://localhost/aa/index.html 就会找通过aa 当做E:\\test这个路径

然后去找这个路径下的index.html文件

location /aa/ {

alias E:\\test\\;

}

root

在使用root的时候,这里的/cc/必须要在E:\\test文件夹下创建一个cc的文件夹,

root的location 对应的cc 必须是真实存在的文件夹的名称,不能随便命名

下面的root 指向你的文件夹的路径,然后浏览器访问 http://localhost/cc/dd.html

的时候,会找到E:\\test\\cc文件夹下面的dd.html文件

location /cc/ {

root E:\\test\\;

index index.html index.htm;

}

总结

root的 location 对应的命名规则 ,必须是存在的文件夹的名字

alias的location 对应的命名规则,是可以随便定义的

相关推荐
Skilce17 分钟前
HAProxy
linux·运维·负载均衡
有一个好名字37 分钟前
claude code安装
linux·运维·前端
亮子AI38 分钟前
【Linux】如何拷贝目录?
linux·运维·服务器
starvapour1 小时前
Ubuntu更换显卡驱动后网络消失的问题
linux·运维·ubuntu
Jerryhut1 小时前
服务器BMC配置管理
运维·服务器
fengyehongWorld1 小时前
Linux wsl中使用windows命令
linux·运维·windows
高梦轩2 小时前
Nginx 安全防护与 HTTPS 部署实战文档
nginx·安全·https
shuxiaohua2 小时前
一次现网问题定位-nginx报错upstream sent invalid chunked response while reading upstream
运维·nginx
成都极云科技3 小时前
「算力服务器托管企业」——IDC行业的新方向
运维·服务器
**蓝桉**3 小时前
Prometheus时间出现误差
linux·运维·prometheus