# Expires and if

**URL:** <https://www.ruby-forum.com/t/expires-and-if/208923>\
**Category:** NGINX\
**Created:** [June 30, 2011, 2:37pm UTC](https://www.ruby-forum.com/t/expires-and-if/208923 "2011-06-30T14:37:25Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [June 30, 2011, 2:37pm UTC](https://www.ruby-forum.com/t/expires-and-if/208923/1 "2011-06-30T14:37:25Z")

</div>

Hello,

I have a complex server configuration and I need to set up “Expires”  
header by mime/types like apache can do  
([mod\_expires - Apache HTTP Server Version 2.4](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](http://backend1);  
}

location ~ ^/d-c-l {  
proxy\_pass [http://backend2](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
