需求:由于運營商緩存社搅,需要域名后加上時間以便繞過緩存喳篇,例:
www.name.com/yyyy-mm-dd/
和www.name.com
返回同樣的數(shù)據(jù)服赎,這時候就需要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;
}