View previous topic :: View next topic |
Author |
Message |
cenocre -
Joined: 12 Mar 2007 Posts: 47
|
Posted: Tue Jan 29, 2008 7:41 am Post subject: How to do Virtual Hosting with localhost |
|
|
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 |
|
|
rrinc -
Joined: 24 Feb 2006 Posts: 725 Location: Arkansas, USA
|
Posted: Wed Jan 30, 2008 12:30 am Post subject: |
|
|
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 |
|
|
cenocre -
Joined: 12 Mar 2007 Posts: 47
|
Posted: Wed Jan 30, 2008 9:51 am Post subject: catchall Hosts file with wildcards |
|
|
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 |
|
|
TRUSTAbyss -
Joined: 29 Oct 2003 Posts: 3752 Location: USA, GA
|
Posted: Wed Jan 30, 2008 9:40 pm Post subject: |
|
|
The Windows "hosts" file doesn't allow wildcards. |
|
Back to top |
|
|
aprelium -
Joined: 22 Mar 2002 Posts: 6800
|
|
Back to top |
|
|
|