location和rewrite
常见的Nginx正则表达式
location
location种类
精准匹配:location = / {}
一般匹配:location / {}
正则匹配:location ~ / {}
location常用的匹配规则
location 优先级
location 示例说明:
location = / {}
location / {}
location /documents/ {}
location /documents/abc {}
location ^~ /images/ {}
location ~* .(gif|jpg|jpeg)$ {}
location /images/abc {}
location ~ /images/abc {}
location /images/abc/1.html {}
优先级
(location =) > (location 完整路径) > (location ^~ 路径) > (location ,* 正则顺序) > (location 部分起始路径) > (location /)
实际网站使用中,至少有三个匹配规则定义
rewrite
rewrite 跳转实现
rewrite执行顺序
执行server块里面的rewrite指令
执行location匹配
执行选定的location中的rewrite指令