# Sub domain trickery

**URL:** <https://www.ruby-forum.com/t/sub-domain-trickery/201235>\
**Category:** NGINX\
**Created:** [January 3, 2011, 1:01pm UTC](https://www.ruby-forum.com/t/sub-domain-trickery/201235 "2011-01-03T13:01:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [January 3, 2011, 1:01pm UTC](https://www.ruby-forum.com/t/sub-domain-trickery/201235/1 "2011-01-03T13:01:23Z")

</div>

Not sure if this is possible, but I am wanting to make subdomains be  
redirected to specific folders dynamically via the nginx.conf file. so  
my DNS would point \*.domain.com to the server. and depending on what the  
person typed in for the subdomain, for example [folder1.domain.com](http://folder1.domain.com) it  
would point them to ~/public\_html/folder1 for the site files.  
[folder2.domain.com](http://folder2.domain.com) \>\> site files in ~/public\_html/folder2.

So if the folder exists, it goes there otherwise, goes 404.

Is this possible to pull off dynamically?

Thanks for thoughts on this.

jared

Posted at Nginx Forum:

> **[sub domain trickery](https://forum.nginx.org/read.php?2,163076,163076#msg-163076)**
>
> Not sure if this is possible, but I am wanting to make subdomains be redirected to specific folders dynamically via the nginx.conf file. so my DNS would point \*.domain.com to the server. and depending on what the person typed in for the subdomain,...

---

<div class="post-metadata">

**Author:** ![cjaredrun](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/2bfe46/32.png) [@cjaredrun](https://www.ruby-forum.com/u/cjaredrun)\
**Post date:** [January 3, 2011, 11:47pm UTC](https://www.ruby-forum.com/t/sub-domain-trickery/201235/2 "2011-01-03T23:47:41Z")

</div>

Hello!

On Mon, Jan 03, 2011 at 07:00:12AM -0500, cjaredrun wrote:

> Thanks for thoughts on this.

Something like this should work:

server {  
server\_name ~^(?).example.com$;  
root /path/to/public\_html/$domain;  
}

Maxim D.
