# Multiple blocks or single reg exp

**URL:** <https://www.ruby-forum.com/t/multiple-blocks-or-single-reg-exp/210119>\
**Category:** NGINX\
**Created:** [July 31, 2011, 3:28pm UTC](https://www.ruby-forum.com/t/multiple-blocks-or-single-reg-exp/210119 "2011-07-31T15:28:13Z")\
**Posts on this page:** 3\
**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:** [July 31, 2011, 3:28pm UTC](https://www.ruby-forum.com/t/multiple-blocks-or-single-reg-exp/210119/1 "2011-07-31T15:28:13Z")

</div>

Hello,  
which would be the best way to handle this multiple location blocks or a  
single location block with a regular exp.

location /css/ { root /var/www/static\_includes/; expires 97d; }  
location /images/ { root /var/www/static\_includes/; expires 97d; }  
location /js/ { root /var/www/static\_includes/; expires 97d;}

* * *

location ~ /(css|images|js)/ {  
root /var/www/static\_includes/;  
expires 97d;  
}

Thanks.

Posted at Nginx Forum:

> **[multiple blocks or single reg exp](https://forum.nginx.org/read.php?2,213142,213142#msg-213142)**
>
> Hello, which would be the best way to handle this multiple location blocks or a single location block with a regular exp. location /css/ { root /var/www/static\_includes/; expires 97d; } location /images/ { root /var/www/static\_includes/; expires 97d;...

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [July 31, 2011, 3:41pm UTC](https://www.ruby-forum.com/t/multiple-blocks-or-single-reg-exp/210119/2 "2011-07-31T15:41:15Z")

</div>

Hello!

On Sun, Jul 31, 2011 at 09:27:41AM -0400, token wrote:

> location ~ /(css|images|js)/ {  
> root /var/www/static\_includes/;  
> expires 97d;  
> }

Use multiple normal location blocks.

Regexp locations do introduce unneeded complexity and make  
configuration maintenance much harder. Besides that, (a) it’s  
easy to make regexp incorrectly (e.g. you missed “^”) and (b)  
normal locations are faster (though you wouldn’t likely notice).

Maxim D.

---

<div class="post-metadata">

**Author:** ![token](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/e0b2c6/32.png) [@token](https://www.ruby-forum.com/u/token)\
**Post date:** [July 31, 2011, 3:56pm UTC](https://www.ruby-forum.com/t/multiple-blocks-or-single-reg-exp/210119/3 "2011-07-31T15:56:04Z")

</div>

Thanks for pointing that out. Locations it is then Thanks again Maxim!

Posted at Nginx Forum:

> **[Re: multiple blocks or single reg exp](https://forum.nginx.org/read.php?2,213142,213145#msg-213145)**
>
> Hello, which would be the best way to handle this multiple location blocks or a single location block with a regular exp. location /css/ { root /var/www/static\_includes/; expires 97d; } location /images/ { root /var/www/static\_includes/; expires 97d;...
