服务器 
首页 > 服务器 > 浏览文章

nginx location 配置 正则表达式实例详解

(编辑:jimmy 日期: 2024/5/10 浏览:3 次 )

1.location 介绍

"htmlcode">

 server {
    listen    8861;
    server_name abc.com;
  }

2.1 “=” 精确匹配

"htmlcode">

location = / {
  .....
}
# 只匹配http://abc.com
# http://abc.com [匹配成功]
# http://abc.com/index [匹配失败]

2.2 “~”,大小写敏感

 例·:

location ~ /Example/ {
  .....
}
#http://abc.com/Example/ [匹配成功]
#http://abc.com/example/ [匹配失败]

2.3.“~*”,大小写忽略

 例:

location ~* /Example/ {
  .....
}
# 则会忽略 uri 部分的大小写
#http://abc.com/test/Example/ [匹配成功]
#http://abc.com/example/ [匹配成功]

2.4.“^~”,只匹配以 uri 开头

 例:

location ^~ /index/ {
  .....
}
#以 /img/ 开头的请求,都会匹配上
#http://abc.com/index/index.page  [匹配成功]
#http://abc.com/error/error.page [匹配失败]

2.5.“@”,nginx内部跳转

 例:

location /index/ {
  error_page 404 @index_error;
}
location @index_error {
  .....
}
#以 /index/ 开头的请求,如果链接的状态为 404。则会匹配到 @index_error 这条规则上。

2.6 不加任何规则

"htmlcode">

location /index/ {
  ......
}
#http://abc.com/index  [匹配成功]
#http://abc.com/index/index.page  [匹配成功]
#http://abc.com/test/index  [匹配失败]
#http://abc.com/Index  [匹配失败]
# 匹配到所有uri
location / {
  ......
}

总结

以上所述是小编给大家介绍的nginx location 配置 正则表达式,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!

上一篇:Linux创建进程达到65535的方法
下一篇:详解linux系统下pid的取值范围
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网