Rewrite rule for cache busting URLs

Igor Sysoev igor at sysoev.ru
Thu Jun 10 00:10:54 MSD 2010


On Wed, Jun 09, 2010 at 03:56:36PM -0400, bkirkbri wrote:

> I understand perfectly.  Being clever with lots of rewrites and regexs does make the config shorter but we have been bitten in the past by unintended side-effects of all that rewrite chaining (in Apache).

You want to keep making the same mistake. nginx allows to make easily
maintainable configuration. Just forget about rewrites. You should
think how to map URI to file system, but not how to rewrite it.

> I'll go with the verbose config with lots of comments then. :)

If I were you, I would place all "/r\d+" regexs inside literal "/r"
location without any comments:

location /r {

    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 /path/to/resources/$1;
        add_header Cache-Control 'public, max-age=2592000'; # 30 days
    }

    ...

    return 404;
}

location /some/resources {
    alias /path/to/resources;
}

This allows to minimize maintaince issues.


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



More information about the nginx mailing list