nginx 2 参数解析

2018-01-28  本文已影响0人  jingqian_xi

上一篇文章介绍了安装nginx的过程,这篇文章来记录一下nginx中配置多个server时的匹配顺序。关于安装请查看安装nginx

首先我们先看一下匹配的几个模式

  1. 精确匹配 (=)
location = /static/index.html{
  root /home/a/xxx/static;
  rewrite "/(xxx/static/)(.*)/" "$2";
}
  1. 普通匹配 (^~)
    备注:不写符号或者写^~都是普通的匹配
location  /static/index.html{
  root /home/a/xxx/static;
  rewrite "/(xxx/static/)(.*)/" "$2";
}
location ^~ /static/index.html{
  root /home/a/xxx/static;
  rewrite "/(xxx/static/)(.*)/" "$2";
}
  1. 正则匹配 (~)
location ~ /static/index.html{
  root /home/a/xxx/static;
  rewrite "/(xxx/static/)(.*)/" "$2";
}

然后看一下location如何发挥作用的

location.jpg

匹配顺序
= 优于 ^~ 优于 ~

小注

上一篇下一篇

猜你喜欢

热点阅读