小编Chr*_*aro的帖子

Nginx 位置正则表达式不匹配

以下一直在为我缓存 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, …
Run Code Online (Sandbox Code Playgroud)

nginx regex

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

nginx ×1

regex ×1