以下一直在为我缓存 css 和 js:
location ~ "^(.*)\.(min.)?(css|js)$" {
expires max;
}
Run Code Online (Sandbox Code Playgroud)
结果:
$ curl -I http://mysite.com/test.css
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 16 Jan 2014 18:55:28 GMT
Content-Type: text/css
Content-Length: 19578
Last-Modified: Mon, 13 Jan 2014 18:54:53 GMT
Connection: keep-alive
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Cache-Control: max-age=315360000
X-Backend: stage01
Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用 10 位 unix 时间戳为我的 js/css 设置版本控制,并且在使用以下有效正则表达式获取正则表达式匹配时遇到问题。
location ~ "^(.*)([\d]{10})\.(min\.)?(css|js)$" {
expires max;
}
Run Code Online (Sandbox Code Playgroud)
结果:
$ curl -I http://mysite.com/test_1234567890.css
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 16 Jan 2014 19:05:03 GMT
Content-Type: text/css
Content-Length: 19578
Last-Modified: Mon, 13 Jan 2014 18:54:53 GMT
Connection: keep-alive
X-Backend: stage01
Accept-Ranges: bytes
Run Code Online (Sandbox Code Playgroud)
我会尝试在 \d 周围不加括号,括号通常用于连续字符或数字,你的括号表示匹配字符“\”或“d”
"^(.*)(\d{10})\.(min\.)?(css|js)$"
Run Code Online (Sandbox Code Playgroud)
另外,您是否专门保存了在括号内捕获的组信息?
为了澄清下面的评论。
从简单开始。
"^.*[0-9]*\.css$"
"^.*[:digit:]*\.css$"
"^.*\d*\.css$"
Run Code Online (Sandbox Code Playgroud)
根据具体情况,使用该数字基数并按如下方式扩展。
"^.*\d{10}\.(min\.)?(css|js)$"
Run Code Online (Sandbox Code Playgroud)
如果您也匹配 http/https,则可以从下面的 http/s 内容开始,记住更改为有效的数字表示法。
"^http(s)?://.*[0-9]{10}\.(min\.)?(css|js)$"
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
10490 次 |
最近记录: |