nginx中location常用配置规则

2019-07-28  本文已影响0人  我老婆的专属情人

location匹配相关说明:

location匹配优先级情况说明:优先级参考以下顺序
注:如果一个url同时适合多个匹配规则,则以第一个为准*

  1. 普通location中= 精确匹配
  2. 普通location中url精确匹配
  3. 普通location中^~匹配
  4. 正则匹配
  5. 通用匹配

常见案例:

# 普通字符匹配:以images为前缀
location ^~ /images/ {
    root /huxm/resources/;
}
# 正则匹配:包含images的
location ~ images {
    root   /huxm/resources/;
}
# 正则匹配: xx.jpg 或xx.png 或  xx.fif
location ~ .*\.(jpg|png|gif)$ {
    root /huxm/resources/images/;
}
# 正则匹配:访问index.html
location ~ "index.html" {
    root   /huxm/resources/html/dist/;
}


上一篇 下一篇

猜你喜欢

热点阅读