Nginx location regex is not matching

Posted by shtuff.it on Server Fault See other posts from Server Fault or by shtuff.it
Published on 2014-01-16T19:05:19Z Indexed on 2014/08/25 4:23 UTC
Read the original article Hit count: 531

Filed under:
|

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

© Server Fault or respective owner

Related posts about nginx

Related posts about regex