How do you setup subdomains on test server?

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.

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.

Steve Ross 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.

http://blog.7thcross.com/?p=7

Chris Olsen wrote:

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/

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