# How do you setup subdomains on test server?

**URL:** <https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421>\
**Category:** Rails\
**Created:** [January 29, 2008, 1:35am UTC](https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421 "2008-01-29T01:35:47Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 1:35am UTC](https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421/1 "2008-01-29T01:35:47Z")

</div>

For testing purposes I need to be able to setup my local testing server  
to allow for subdomains, ie subdomain.localhost:3000. The way things  
are set up now it will tell me the page cannot be found.

I included \*.localhost in my /etc/hosts file, but that doesn’t seem to  
do the trick.

Thanks for the help.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 3:37am UTC](https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421/2 "2008-01-29T03:37:12Z")

</div>

On Jan 28, 2008, at 4:35 PM, Chris O. wrote:

> –  
> I usually set up things in my hosts file to point to my port 80 server  
> (which is normally Apache). I then have Apache resolve the subdomains  
> and send the requests via virtual hosts to the mongrels listening on  
> various ports. Seems like a lot for a local installation, but  
> sometimes you need to be able to test that kind of functionality.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 4:37am UTC](https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421/3 "2008-01-29T04:37:03Z")

</div>

Steve R. wrote:

> On Jan 28, 2008, at 4:35 PM, Chris O. wrote:
> 
> > –  
> > I usually set up things in my hosts file to point to my port 80 server  
> > (which is normally Apache). I then have Apache resolve the subdomains  
> > and send the requests via virtual hosts to the mongrels listening on  
> > various ports. Seems like a lot for a local installation, but  
> > sometimes you need to be able to test that kind of functionality.

Thanks for the tip Steve.

It seems like it doesn’t like the \*. If I use something like the  
following it works fine, which is ok for testing.

# /etc/hosts

127.0.0.0 localhost test1.localhost test2.localhost

I also found a really good article in the Advanced Rails Recipes book,  
which went over other details related to session cookies and if the  
client is being redirected by a custom url.

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 10:52am UTC](https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421/4 "2008-01-29T10:52:20Z")

</div>

On 29 Jan 2008, at 04:37, Chris O. wrote:

> following it works fine, which is ok for testing.
> 
> # /etc/hosts
> 
> 127.0.0.0 localhost test1.localhost test2.localhost
> 
> I also found a really good article in the Advanced Rails Recipes book,  
> which went over other details related to session cookies and if the  
> client is being redirected by a custom url.

If you’re on MacOS X, you can use this blog post to make it more  
general:

[http://woss.name/2006/11/13/setting-up-local-name-server-on-mac-os-x/](http://woss.name/2006/11/13/setting-up-local-name-server-on-mac-os-x/)

I have a few domains I set up:  
\*.specificapplication.rails (this application uses subdomain  
authentication)  
\*.dev.rails (this is a general domain I use for all other  
applications, I use the subdomain part for the application name).  
The big advantage of the last one, is that you get a new session for  
each application.

myapp1.dev.rails:3000 =\> is logged in  
myapp2.dev.rails:4000 =\> is also logged in

If you’re using localhost as the url for everything, the session is  
shared if you switch between applications and that can be troublesome  
at times.

Best regards

Peter De Berdt

---

<div class="post-metadata">

**Author:** ![chrisolsen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/c6cbf5/32.png) [@chrisolsen](https://www.ruby-forum.com/u/chrisolsen)\
**Post date:** [January 29, 2008, 8:24am UTC](https://www.ruby-forum.com/t/how-do-you-setup-subdomains-on-test-server/127421/5 "2008-01-29T08:24:21Z")

</div>

[http://blog.7thcross.com/?p=7](http://blog.7thcross.com/?p=7)

Chris O. wrote:

> For testing purposes I need to be able to setup my local testing server  
> to allow for subdomains, ie subdomain.localhost:3000. The way things  
> are set up now it will tell me the page cannot be found.
> 
> I included \*.localhost in my /etc/hosts file, but that doesn’t seem to  
> do the trick.
> 
> Thanks for the help.
