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 2012-12-14 12:32
on 2012-12-14 12:39
On Fri, Dec 14, 2012 at 6:31 PM, howard chen <howachen@gmail.com> 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?
on 2012-12-14 13:00
> 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 2012-12-14 13:38
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 Sysoev http://nginx.com/support.html
on 2012-12-14 15:39
Hi On Fri, Dec 14, 2012 at 7:59 PM, Antonio P.P. Almeida <appa@perusio.net>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..
on 2012-12-14 15:44
Hi Ignor On Fri, Dec 14, 2012 at 8:37 PM, Igor Sysoev <igor@sysoev.ru> 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?
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.