How to do Virtual Hosting with localhost

 
Post new topic   Reply to topic    Aprelium Forum Index -> Tutorials
View previous topic :: View next topic  
Author Message
cenocre
-


Joined: 12 Mar 2007
Posts: 45

PostPosted: Tue Jan 29, 2008 7:41 am    Post subject: How to do Virtual Hosting with localhost Reply with quote

For testing sites it is great to have local site (only accessible to you) that is operationally identical to your public site while still having access to your public sites in the same browser. Doing the local virtual hosts setup is useful for testing sites locally where you get full use of relative links before opening sites up to the web.

It is much easier than generally presented in the forums. All you have to to is modify your local host file and slightly modify your normal virtual hosts setup.

STEP 1

Locate your hosts file. The path is /private/etc/hosts on Macs and is similar on Windoze and Linux. Open the hosts file in a text editor and after the line:

127.0.0.1 localhost

add a line

127.0.0.1 virtualhostname

for each virtual host

The virtual host name does NOT have to be a registered domain or even a properly formatted domain syntax. It can be a single word or whatever. What I do is take one of my regular domains and simply change the .com or .org to .dev so the file looks like this:

127.0.0.1 localhost
127.0.0.1 virtualhostname1.dev
127.0.0.1 virtualhostname2.dev
127.0.0.1 testsite

By using the .dev extension, regular requests to the domain go to the regular site and the .dev requests stay local.

STEP 2

For a server doing only local hosting: Using names matching what you put in the Hosts file, set up the virtual hosts file as normal, except for each virtual host, add virtualhostname.dev or *virtualhostname.dev to each virtual host. You can have the same configuration on both your test and live machines.

For a server that has local test sites and identical live sites: The test and live sites will have to have different virtual host records as they will be in different folders.

STEP 3

You are all ready. On your local machine just type the local virtual host name such as virtualhostname.dev or testname in your browser and you go to your local site. virtualhostname.com will still take you to the public site.
Back to top View user's profile Send private message
rrinc
-


Joined: 24 Feb 2006
Posts: 725
Location: Arkansas, USA

PostPosted: Wed Jan 30, 2008 12:30 am    Post subject: Reply with quote

Looks good.

Hosts path on Windows: '%windir%\system32\drivers\etc\hosts'

I think the typical path on Linux is 'etc/hosts'
_________________
-Blake | New Server :D
SaveTheInternet
Soy hispanohablante. Puedes contactarme por mensajes privados.
Back to top View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
cenocre
-


Joined: 12 Mar 2007
Posts: 45

PostPosted: Wed Jan 30, 2008 9:51 am    Post subject: catchall Hosts file with wildcards Reply with quote

Just tried to do it as it would greatly simplify everything, but apparently won't work as wildcards don't work in the hosts file.

What I wish to do is this:

127.0.0.1 localhost
127.0.0.1 *.dev

so it would capture ANY .dev extension and keep one from having to modify the hosts file for each VH.

Any ideas on how to achieve that ease?

Apache has Module mod_vhost_alias ( http://httpd.apache.org/docs/1.3/mod/mod_vhost_alias.html ) that goes part way there with its implementation of dynamic virtual hosting. Great idea, but want nothing to do with Apache anymore.
Back to top View user's profile Send private message
TRUSTAbyss
-


Joined: 29 Oct 2003
Posts: 3714
Location: USA, GA

PostPosted: Wed Jan 30, 2008 9:40 pm    Post subject: Reply with quote

The Windows "hosts" file doesn't allow wildcards.
_________________
Computer Programmer & Networking Specialist

Back to top View user's profile Send private message Visit poster's website MSN Messenger
aprelium
-


Joined: 22 Mar 2002
Posts: 6800

PostPosted: Thu Jan 31, 2008 5:03 pm    Post subject: Re: How to do Virtual Hosting with localhost Reply with quote

cenocre,

Thank you for the detailed tutorial. It gives extensive instructions in comparison with our article http://www.aprelium.com/abyssws/articles/access-test.html .
_________________
Support Team
Aprelium - http://www.aprelium.com
Back to top View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Tutorials All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group