nginx location 匹配命令
~ #正则匹配,区分大小写
~* #正则匹配,不区分大小写
^~ #普通字符匹配,一般用来匹配目录
= #普通字符精确匹配
=(精确匹配) > ^~(普通字符匹配) > ~*(正则匹配) > 完全路径
nginx location 匹配优先级
1.= 精确匹配。发现精确匹配,nginx停止搜索其他匹配模式。
location = nginx {
...
}
2.普通字符匹配
location /nginx {
...
}
3.^~ 匹配该规则
location ^~ /nginx {
...
}
4.~* 如果找到相应的匹配
location ~* /nginx {
...
}
1.last 停止当前这个请求,并根据rewrite匹配的规则重新发起一个请求
2.break 终止匹配, 不再匹配后面的规则
3.redirect 返回302临时重定向 显示跳转后的地址
4.permanent 301永久重定向 显示跳转后的地址
location = nginx {
rewrite ^/nginx(.*)$ https://nginx.location.com/$1 permanent;
# ^/nginx(.*) 正则表达式
}