Nginx location regex is not matching
- by shtuff.it
The following has been working to cache css and js for me:
location ~ "^(.*)\.(min.)?(css|js)$" {
expires max;
}
results:
$ 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
I am trying to get versioning setup for my js / css using a 10 digit unix timestamp and am having issues getting a regex match with the following valid a regex.
location ~ "^(.*)([\d]{10})\.(min\.)?(css|js)$" {
expires max;
}
results:
$ 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