Setting expires header to multiple locations

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;
}
}

=====================================

Are there any better way to write it?

Thanks.

On Fri, Dec 14, 2012 at 6:31 PM, howard chen [email protected] wrote:

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

}

=====================================

Are there any better way to write it?

put in separate file and include it in each blocks?

    expires 1y;
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

On Dec 14, 2012, at 15:59 , Antonio P.P. Almeida wrote:

   expires 1y;

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;
}

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;
}
}

Of course this requires more time to type, but allows me to spend much
less time when I need to modify configuration in future.


Igor S.
http://nginx.com/support.html

Hi Ignor

On Fri, Dec 14, 2012 at 8:37 PM, Igor S. [email protected] wrote:

   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?

Hi

On Fri, Dec 14, 2012 at 7:59 PM, Antonio P.P. Almeida
[email protected]wrote:

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;
}

Thanks.

My example just in a simplified form and there are more config inside
each
a, b, c…So I must need separate blocks for them…

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs