expires and if
Jérôme Loyet
jerome at loyet.net
Thu Jun 30 16:36:35 MSD 2011
Hello,
I have a complex server configuration and I need to set up "Expires"
header by mime/types like apache can do
(http://httpd.apache.org/docs/current/mod/mod_expires.html#expiresbytype).
I can't use locations because I already have a lots of them and they
would override each others. With the following configuration
server {
...
root /var/www/site1/docroot;
location /bo {
root /var/www/bo;
}
location /fo {
root /var/www/fo;
}
location ~ \.php {
proxy_pass http://backend1;
}
location ~ ^/d-c-l {
proxy_pass http://backend2;
}
location ~ \.(?:css|jpg)$ {
expires max;
}
}
/bo/toto.html will be handle by the "/bo" location whereas
/bo/toto.css will be handle by the "~ \.(?:css|jpg)" location and
return 404 because of the wrong docroot.
I've tried to use expires with variables but it's not working
(directive invalid value). So I've tried to use expires in an "if"
block but it only works if the "if" block is inside a "location"
block. Which means that I will have to add an if block in every
location I have (which is complicated in my configuration).
Why is the following conf does not work
server {
...
if ($request_uri ~ \.css) {
expires max;
}
}
whereas the following one works:
server {
...
location / {
if ($request_uri ~ \.css) {
expires max;
}
}
}
Anyway, if you have a tips to help me on this, I'm all in
++ Jerome
More information about the nginx
mailing list