Shoutbox

[Fixed] Multiple VirtualHosts? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: [Fixed] Multiple VirtualHosts? (/showthread.php?tid=67699)

[Fixed] Multiple VirtualHosts? by hmaster on 10-26-2006 at 10:38 AM

I have a Apache server running on my desktop and I was wondering how I can get more than one virtual host, eg http://localhost/ is currently pointed to my main folder but I'd like another one, http://localhost2/ or w/e, to point to another folder for a specific site.

I've been told it is possible but I can't find a tutorial that has actualy worked.

Running:
Apache 2
PHP 5


Any help appreciated, thanks.


Solution:
In the hosts file it should look like:

code:
127.0.0.1 name1
127.0.0.2 name2
127.0.0.3 name3
And in the httpd.conf file it should be like this:
code:
<VirtualHost 127.0.0.1>
    DocumentRoot C:/path
    ServerName name1
</VirtualHost>

<VirtualHost 127.0.0.2>
    DocumentRoot C:/path/to2
    ServerName name2
</VirtualHost>

<VirtualHost 127.0.0.3>
    DocumentRoot C:/path/to/it
    ServerName name3
</VirtualHost>

RE: Multiple Localhosts? by Sypher on 10-26-2006 at 12:03 PM

First of all, for these things don't use "localhosts" but virtualhosts.

In the apache config you can create virtual hosts.

Apache 2.2: http://httpd.apache.org/docs/2.2/vhosts/
Apache 2.0: http://httpd.apache.org/docs/2.0/vhosts/

In the apache config you add:

code:
NameVirtualHost *

If you want him to listen at all IP's you have.

Then for the vhosts, add this:
code:
<VirtualHost 123.123.123.123>
ServerAdmin webmaster@host.foo.com
DocumentRoot /www/docs/host.foo.com
ServerName host.foo.com
ErrorLog logs/host.foo.com-error_log
TransferLog logs/host.foo.com-access_log
</VirtualHost>
and for the second one
code:
<VirtualHost 123.123.123.123>
ServerAdmin webmaster@host.foo2.com
DocumentRoot /www/docs/host.foo2.com
ServerName host.foo2.com
ErrorLog logs/host.foo2.com-error_log
TransferLog logs/host.foo2.com-access_log
</VirtualHost>

You should adapt these things to your own settings, like the IP.

If you want to create "localhost2" you can edit your hostsfile.
In Windows XP this is located at
c:\WINDOWS\system32\drivers\etc\hosts

Normally it would look like this:
code:
127.0.0.1       localhost

Change it to

code:
127.0.0.1       localhost
127.0.0.1       localhost2

Should work. Good luck!
RE: Multiple VirtualHosts? by hmaster on 10-26-2006 at 01:24 PM

quote:
Originally posted by Sypher
First of all, for these things don't use "localhosts" but virtualhosts.

Thanks.

quote:
Originally posted by Sypher
Long post...
It recognises that there is a second vhost but doesn't allow me to view files.

RE: Multiple VirtualHosts? by Sypher on 10-31-2006 at 01:56 PM

Try checking the logfiles then :)


RE: Multiple VirtualHosts? by Adeptus on 10-31-2006 at 02:55 PM

You are probably missing a <Location> directive telling the server it is allowed to serve files under whatever the local path for the files is.

There is no substitute to thorough reading of the documentation.  :P