需求:由于运营商缓存,需要域名后加上时间以便绕过缓存,例:
www.name.com/yyyy-mm-dd/
和www.name.com
返回同样的数据,这时候就需要nginx的正则匹配
写法
location ~ ^/\d+\-\d+\-\d+/(.*)$ {
alias /etc/nginx/html/$1;
}
- 重点是
()
和$1
,如果不写,会报404/403 - nginx文档:
If alias is used inside a location defined with a regular expression then such regular expression should contain captures and alias should refer to these captures (0.7.40), for example:
location ~ ^/users/(.+\.(?:gif|jpe?g|png))$ {
alias /data/w3/images/$1;
}
网友评论