Expires .. is there a way to set an expires header for all of jpg, gif, css, js ?

Rob Schultz rschultz7 at gmail.com
Sat Sep 6 22:37:20 MSD 2008

It should work with underscores, hyphen's etc. as its grabbing all char's
from the .+ that should match all char's that is not a line break.
Also about ignoring root. I set my root in the base of the server config. IE
        server {
                listen          80;
                server_name     domain.org www.domain.org;

                access_log      /var/log/nginx/domain.org.access_log main;
                error_log       /var/log/nginx/domain.org.error_log info;

                root /var/www/domain.org/htdocs;

                location ~ .*\.php$ {
                        fastcgi_index   index.php;

                location ~* ^.+\.(jpg|jpeg|gif|png)$ {
                        access_log   off;
                        expires      30d;

I try to keep everything at the lowest part that i need it. I use the index
directive in the main http section as most of my sites will use those. And
if i need custom then i will adjust in each of my server sections. Same
thing with my server sections. i do a root in the toplevel of the server
directive so everything works no matter what i do and then IF i need a
location to go somewhere else i put that inside the location. I think this
is easier and solves alot of issues of having to remember to put them in
multiple location's etc etc. Only overwrite it if you need it.

On Sat, Sep 6, 2008 at 12:55 PM, David <mishy.cth at gmail.com> wrote:

> Hi Rob,
> I've managed to get this working now:
>        Location ~* ^.+\.(jpg|jpeg|gif|png)$ {
>            access_log        off;
>            expires           30d;
>        }
> I needed to specify the root or it would default to nginx's default
> docroot.
> Your regex works well, but only works for images without underscores,
> hyphens,
> or anything infact that isn't just a continuous text string. Would it be
> easy
> enough to modify in order to cope with this ?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx/attachments/20080906/aefd6fd4/attachment.html>

More information about the nginx mailing list