美文网首页
nginx:location、root/alias

nginx:location、root/alias

作者: 追风还是少年 | 来源:发表于2024-02-02 23:21 被阅读0次

location

location [ = | ~ | ~* | ^~] uri {
}

uri可以包含正则表达式(正则uri),也可以不包含正则表达式(标准uri)
(1)=,严格匹配
(2)~,用于标识uri包含正则表达式,并且区分大小写
(3)~*,用于标识uri包含正则表达式,并且不区分大小写
(4)^~,用于标准uri前,要求nginx服务器找到标识uri和请求字符串匹配度最高的location后,立即使用此location处理请求,而不再使用location块中的正则uri和请求字符串做匹配

root/alias

(1) root,配置请求的根路径
location /data/
{
root /locationtest1;
}
当location块收到/data/index.html的请求时,将在/locationtest1/data/目录下找到index.htm响应请求

(2)alias,更改location的uri
location ~ ^/data/(.+.(htm | html)){ alias /locationtest1/other/1;
}
当此location块接收到/data/index.htm的请求时,匹配成功,之后根据alias指令的配置,nginx服务器将到locationtest1/other目录下找到index.htm并响应请求

相关文章

网友评论

      本文标题:nginx:location、root/alias

      本文链接:https://www.haomeiwen.com/subject/pkgtadtx.html