Setting expires header to multiple locations

howard chen howachen at gmail.com
Fri Dec 14 14:43:39 UTC 2012


Hi Ignor

On Fri, Dec 14, 2012 at 8:37 PM, Igor Sysoev <igor at sysoev.ru> wrote:
>
>
> This valid only if "~* /b" was intended for "~* ^/b".
>
> As to me, I prefer to isolate regex locations (if I have to use them at
> all)
> inside usual locations:
>
> location /c {
>    location ~* \.(?:css|js|jpg|jpeg|gif|png)$ {
>        expires 1y;
>    }
> }
>
>
My issue is in nginx, url can only be matched to only ONE location, unlike
in Apache we have something like * ExpiresByType*, seems duplicate
 multiple locations is a must in nginx.

e.g.


location ~* /a {
    location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ {
        expires 1y;
    }

    # more unique config for /a, cannot be combined
}

location ~* /b {
    location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ {
        expires 1y;
    }

    # more unique config for /b, cannot be combined
}

location ~* /c {
    location ~* ^/.*\.(?:css|js|jpg|jpeg|gif|png)$ {
        expires 1y;
    }

    # more unique config for /c, cannot be combined
}


Any better way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20121214/5f733439/attachment.html>


More information about the nginx mailing list