Setting expires header to multiple locations
    Antonio P.P. Almeida 
    appa at perusio.net
       
    Fri Dec 14 11:59:49 UTC 2012
    
    
  
> Currently I need to use tricks since I have multiple locations in my site
> config.
>
> e.g.
>
> =====================================
>
>
> location ~* /a {
>     location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ {
>         expires 1y;
>     }
> }
>
> location ~* /b {
>     location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ {
>         expires 1y;
>     }
> }
>
> location ~* /c {
>     location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ {
>         expires 1y;
>     }
> }
Going against Igor, Maxim, Valentin and Ruslan in order to be more DRY you
could use a regex based location (which has its own quirks):
location ~* ^/(?:a|b|c)/.*\.(?:css|gif|js|jpe?g|png)$ {
    expires 1y;
}
--appa
    
    
More information about the nginx
mailing list