【发布时间】:2017-05-06 19:20:00
【问题描述】:
Web 项目在 /content/img 文件夹中有静态内容。 url 规则是:/img/{some md5} 但在文件夹中的位置:/content/img/{前两位数}/
例子
url: example.com/img/fe5afe0482195afff9390692a6cc23e1
location: /www/myproject/content/img/fe/fe5afe0482195afff9390692a6cc23e1
这个 nginx 位置是正确的,但很多不安全(符号点在正则表达式中不好):
location ~ /img/(..)(.+)$ {
alias $project_home/content/img/$1/$1$2;
add_header Content-Type image/jpg;
}
下一个位置更正确,但不起作用:
location ~ /img/([0-9a-f]\{2\})([0-9a-f]+)$ {
alias $project_home/content/img/$1/$1$2;
add_header Content-Type image/jpg;
}
帮我找出错误以获得更正确的 nginx 位置。
【问题讨论】:
-
试试
/img/([0-9a-fA-F]{2})([0-9a-fA-F]+)$(见this demo)。
标签: regex nginx nginx-location