# Multiple vhosts with wildcards?

**URL:** <https://www.ruby-forum.com/t/multiple-vhosts-with-wildcards/129645>\
**Category:** NGINX\
**Created:** [February 20, 2008, 11:00am UTC](https://www.ruby-forum.com/t/multiple-vhosts-with-wildcards/129645 "2008-02-20T11:00:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [February 20, 2008, 11:00am UTC](https://www.ruby-forum.com/t/multiple-vhosts-with-wildcards/129645/1 "2008-02-20T11:00:00Z")

</div>

Hi

At the moment we’re using lighttpd, but its proving to be a little flaky  
with php-fcgi. I’d like to know whether its possible to get the  
following set-up working so I can replace lighttpd with nginx.

We use a _lot_ of wildcard domains. The subdomains correspond to a  
client, and they have their own areas:

review._.ourdomain.com  
mail._.ourdomain.com  
dev.\*.ourdomain.com  
\*.ourdomain.com

This is pretty trivial to set up in lighttpd:

$HTTP[“host”] =~ “^review.(._).ourdomain.com" {}  
$HTTP[“host”] =~ "^mail.(._).ourdomain.com” {}  
$HTTP[“host”] =~ “^dev.(._).ourdomain.com" {}  
$HTTP[“host”] =~ "^(._).ourdomain.com” {}

Trying to set up something similar in nginx raises problems. This is my  
setup:

server {  
server\_name [review.it.ourdomain.com](http://review.it.ourdomain.com) review.\*.ourdomain.com;  
…  
}

server {  
server\_name [dev.it.ourdomain.com](http://dev.it.ourdomain.com) dev.\*.ourdomain.com;  
…  
}

but this just throws the following error:

[emerg] 3320#0: invalid server name or wildcard “dev.\*.ourdomain.com”

## Any idea how I can achieve the result I’m looking for?

_Phillip B Oldham_  
The Activity People  
removed\_email\_address@domain.invalid [mailto:removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

* * *

_Policies_

This e-mail and its attachments are intended for the above named  
recipient(s) only and may be confidential. If they have come to you in  
error, please reply to this e-mail and highlight the error. No action  
should be taken regarding content, nor must you copy or show them to  
anyone.

This e-mail has been created in the knowledge that Internet e-mail is  
not a 100% secure communications medium, and we have taken steps to  
ensure that this e-mail and attachments are free from any virus. We must  
advise that in keeping with good computing practice the recipient should  
ensure they are completely virus free, and that you understand and  
observe the lack of security when e-mailing us.

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [February 20, 2008, 1:39pm UTC](https://www.ruby-forum.com/t/multiple-vhosts-with-wildcards/129645/2 "2008-02-20T13:39:50Z")

</div>

On Wed, Feb 20, 2008 at 09:46:23AM +0000, Phillip B Oldham wrote:

> \*.ourdomain.com
> 
> but this just throws the following error:
> 
> [emerg] 3320#0: invalid server name or wildcard “dev.\*.ourdomain.com”
> 
> ## Any idea how I can achieve the result I’m looking for?

Use regex (note “~”):

server {  
server\_name [review.it.ourdomain.com](http://review.it.ourdomain.com) ~^review..+.ourdomain.com$;  
…  
}

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [February 20, 2008, 2:49pm UTC](https://www.ruby-forum.com/t/multiple-vhosts-with-wildcards/129645/3 "2008-02-20T14:49:47Z")

</div>

> Use regex (note “~”):
> 
> server {  
> server\_name [review.it.ourdomain.com](http://review.it.ourdomain.com) ~^review..+.ourdomain.com$;  
> …  
> }

Cool, never knew that server\_name supported regex. Didn’t see that in  
the English wiki, just cross referencd it in the Russian docs

---

<div class="post-metadata">

**Author:** ![Phillip\_B\_Oldham](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/13edae/32.png) [@Phillip\_B\_Oldham](https://www.ruby-forum.com/u/Phillip_B_Oldham)\
**Post date:** [February 20, 2008, 2:52pm UTC](https://www.ruby-forum.com/t/multiple-vhosts-with-wildcards/129645/4 "2008-02-20T14:52:09Z")

</div>

On Wed, Feb 20, 2008 at 09:39:11PM +0800, Yusuf Goolamabbas wrote:

> > Use regex (note “~”):
> > 
> > server {  
> > server\_name [review.it.ourdomain.com](http://review.it.ourdomain.com) ~^review..+.ourdomain.com$;  
> > …  
> > }
> 
> Cool, never knew that server\_name supported regex. Didn’t see that in  
> the English wiki, just cross referencd it in the Russian docs

It had appeared in 0.6.7 and 0.5.33.
