Welcome! Log In Create A New Profile

Advanced

Re: Rewrite rule for cache busting URLs

June 09, 2010 11:32AM
On Wed, Jun 09, 2010 at 11:21:47AM -0400, bkirkbri wrote:

> 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?

Yes, there is a better way:

location ~ ^/r\d+(/some/resources/.+)$ {
alias /path/to/resources/$1;
add_header Cache-Control 'public, max-age=2592000'; # 30 days
}

location ~ ^/r\d+(/some/other/resources/.+)$ {
alias /some/other/resources/$1;
add_header Cache-Control 'public, max-age=2592000'; # 30 days
}


--
Igor Sysoev
http://sysoev.ru/en/

_______________________________________________
nginx mailing list
nginx@nginx.org
http://nginx.org/mailman/listinfo/nginx
Subject Author Posted

Rewrite rule for cache busting URLs

bkirkbri June 09, 2010 11:21AM

Re: Rewrite rule for cache busting URLs

Igor Sysoev June 09, 2010 11:32AM

Re: Rewrite rule for cache busting URLs

bkirkbri June 09, 2010 12:13PM

Re: Rewrite rule for cache busting URLs

Igor Sysoev June 09, 2010 02:36PM

Re: Rewrite rule for cache busting URLs

bkirkbri June 09, 2010 03:56PM

Re: Rewrite rule for cache busting URLs

Igor Sysoev June 09, 2010 04:14PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 228
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready