Rewrite rule for cache busting URLs
bkirkbri
nginx-forum at nginx.us
Wed Jun 9 19:21:47 MSD 2010
Our application uses versioned URLs like http://domain.com/r123456789/resource/uri to allow for aggressive caching and easy cache invalidation.
To get this working in nginx, I currently have a config like this:
[code]
#################################################
set $cache_control '';
location ~ ^/r\d+/ {
set $cache_control 'public, max-age=2592000'; # 30 days
rewrite ^/r\d+(/.*)$ $1 last;
}
location /some/resources {
if ( $cache_control ) {
add_header Cache-Control $cache_control;
}
alias /path/to/resources;
}
location /some/other/resource {
if ( $cache_control ) {
add_header Cache-Control $cache_control;
}
alias /some/other/path;
}
#################################################
[/code]
Is this a bad idea? Likely to fail in the future? Anyone know a better way?
Could the HTTP Headers module be improved to allow "expires" or "add_header" to be used inside an "if" condition?
Thanks in advance!
Best,
Brian
Posted at Nginx Forum: http://forum.nginx.org/read.php?2,96334,96334#msg-96334
More information about the nginx
mailing list