nginx的重定向(rewrite)
location 匹配
location匹配的就是后面的URI
/wordpress
192.168.11.137/wordpress
location匹配的分类和优先级
1、精确匹配:
location = / 对字符串进行完全匹配,必须完全符合
2、正则匹配:
^~ 前缀匹配,以什么为开头
~ 区分大小写的匹配
~* 不区分大小写
!~ 区分大小写的取反
!~* 不区分大小写的取反
3、一般匹配
location /字符串
精确匹配的优先级最高,正则,一般。
优先级总结:
location = 完整路径 > location ^ > location*=location > location /部分起始位置 > location /
实际网站中的使用规则
网页的首页
location = / {
root html;
index index.html index.htm index.php;
}
第二个必选规则:处理静态请求的页面
location ^~ /static/ {
root /web/static/;
index index.html index,htm;
}
用来匹配静态页面
location ~*\.(jpg.gif|png|jpeg|cs