Nginx:root与alias的区别

简介: Nginx:root与alias的区别

root目录:

root路径 + location路径

alias别名:

alias路径 替换 location路径

例:

location ^~ /dir/ {
    root /www/root/html/;
    # location = /www/root/html/ + /dir/
}
# 请求的URI: /dir/a.html时,返回 /www/root/html/dir/a.html
location ^~ /dir/ {
    alias /www/root/html/;
    # location = /www/root/html/
}
# 请求的URI:/dir/a.html时,返回:/www/root/html/a.html

注意

alias后面必须要用“/”结束,否则会找不到文件,root可有可无。

alias在使用正则匹配时,必须捕捉要匹配的内容并在指定的内容处使用。

alias只能位于location块中。(root可以不放在location中)

^~ 如果路径匹配那么不测试正则表达式

参考

nginx中的root与alias的差别

相关文章
|
10月前
|
应用服务中间件 PHP nginx
当你的nginx服务器和php服务器不在一起的时候,这个nginx 的root目录问题
两个服务器的网站代码目录需要对齐,docker容器里面也是一样
|
应用服务中间件 nginx
Nginx里的root和alias的区别是什么?
Nginx里的root和alias的区别是什么?
914 2
|
前端开发 应用服务中间件 nginx
Nginx中root与alias区别
Nginx中root与alias区别
222 0
|
应用服务中间件 nginx
Nginx 配置中root和alias的区别分析
Nginx 配置中root和alias的区别分析
331 0
|
应用服务中间件 nginx
nginx中alias
nginx中alias
129 0
|
应用服务中间件 Linux nginx
重识Nginx - 06 搭建静态资源Web服务器(alias VS root)
重识Nginx - 06 搭建静态资源Web服务器(alias VS root)
388 0
|
应用服务中间件 nginx
nginx中root和alias的区别
nginx中root和alias的区别
nginx中root和alias的区别
|
应用服务中间件 nginx
Nginx:root与alias的区别
Nginx:root与alias的区别
210 0
|
数据建模 应用服务中间件 nginx
Docker - 解决创建 nginx 容器尝试挂载 nginx.conf 文件时报错: mounting "/root/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" caused: mount through procfd: not a directory:
Docker - 解决创建 nginx 容器尝试挂载 nginx.conf 文件时报错: mounting "/root/nginx.conf" to rootfs at "/etc/nginx/nginx.conf" caused: mount through procfd: not a directory:
3551 0
|
应用服务中间件 nginx