# Would "root" allow for captures?

**URL:** <https://www.ruby-forum.com/t/would-root-allow-for-captures/165212>\
**Category:** NGINX\
**Created:** [April 10, 2009, 7:36am UTC](https://www.ruby-forum.com/t/would-root-allow-for-captures/165212 "2009-04-10T07:36:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 10, 2009, 7:36am UTC](https://www.ruby-forum.com/t/would-root-allow-for-captures/165212/1 "2009-04-10T07:36:41Z")

</div>

i’d like to do something like:

server {  
listen 80;  
server\_name \*.user.foo.com;  
root /home/user/web/$1;  
}

this would be basically required too:

server {  
listen 80;  
server\_name \*.user.foo.com;  
root /home/user/web/$1;  
if ($1 == 'something) {  
require include.conf;  
}  
}

it would be nice if i could assign “user” as a variable too. however,  
that would be a double bonus.

i think alias allows captures, but i would need to define  
DOCUMENT\_ROOT then as well.

ideas?

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 10, 2009, 8:04am UTC](https://www.ruby-forum.com/t/would-root-allow-for-captures/165212/2 "2009-04-10T08:04:44Z")

</div>

perhaps this?

On Fri, Apr 10, 2009 at 12:24 PM, Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> i’d like to do something like:
> 
> server {  
> Â listen 80;  
> Â server\_name _.user.foo.com;  
> server\_name (._?).user.foo.com;

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 10, 2009, 8:10am UTC](https://www.ruby-forum.com/t/would-root-allow-for-captures/165212/3 "2009-04-10T08:10:35Z")

</div>

On Thu, Apr 09, 2009 at 10:24:12PM -0700, Michael S. wrote:

> i’d like to do something like:
> 
> server {  
> listen 80;  
> server\_name \*.user.foo.com;

```
 server_name ~^(.+)\.user\.foo\.com$;

```

> ```
> require include.conf;
> 
> ```
> 
> }  
> }

This i ssome kind of configuration macro, but it’s currently not easy  
to implement this.

> it would be nice if i could assign “user” as a variable too. however,  
> that would be a double bonus.
> 
> i think alias allows captures, but i would need to define  
> DOCUMENT\_ROOT then as well.

The “root” supports captures too.

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 10, 2009, 8:18am UTC](https://www.ruby-forum.com/t/would-root-allow-for-captures/165212/4 "2009-04-10T08:18:12Z")

</div>

2009/4/9 Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Â Â server\_name ~^(.+).user.foo.com$;

awesome! it works.

> > Â Â if ($1 == 'something) {  
> > Â Â Â require include.conf;  
> > Â Â }

> This i ssome kind of configuration macro, but it’s currently not easy  
> to implement this.

really? why is that? seems like it should be pretty straightforward,  
but you know your code the best.

> The “root” supports captures too.

just figured that out - excellent 🙂

---

<div class="post-metadata">

**Author:** ![wickie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/ba9def/32.png) [@wickie](https://www.ruby-forum.com/u/wickie)\
**Post date:** [April 11, 2009, 7:36pm UTC](https://www.ruby-forum.com/t/would-root-allow-for-captures/165212/5 "2009-04-11T19:36:33Z")

</div>

On Thu, Apr 9, 2009 at 11:11 PM, Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > This i ssome kind of configuration macro, but it’s currently not easy  
> > to implement this.

This would also work

include /etc/nginx/$1.conf;

but I would want to test for the existence first.

if (-f /etc/nginx/$1.conf) {  
include /etc/nginx/$1.conf;  
}

so it is not easy to do if ($1 == ‘something’) {} ? if so, then we  
just need to say that include is allowed inside of an if block 🙂
