[Gloucs] apache virtual hosts

Guy Edwards guy_j_edwards at hotpop.com
Sat Sep 18 14:23:58 BST 2004


Hi,

Someone asked about Apache virtual hosts and how to do them but I've
deleted a whole load of emails so I can't reply to it... anyway, just
thought I'd give some instructions if you've not worked it out yet.

setting up virtual hosts with apache;

1) If you're just mucking around then edit your /etc/hosts file to
include your new site, eg:
/etc/hosts
127.0.0.1       portable        localhost
127.0.0.1       www.guy.guy

Although for your intranet/public webserver or whatever you'll need to
alter the DNS so people get directed to your server for the new name.

2) now make a directory for your second website, I just used 
/var/www and /var/www2 for mine.

3) put a simple file in each:
/var/www/index.html 
<html><head></head><body><h1>Site 1</h1></body></html>
/var/www2/index.html 
<html><head></head><body><h1>Site 2</h1></body></html>

4) Now in you configuration file for apache, find where it says
something similar to:

NameVirtualHost *
<VirtualHost *>
        DocumentRoot /var/www/
[..... lots of other stuff ....]
</VirtualHost>

and change it to something along the lines of

NameVirtualHost 127.0.0.1
<VirtualHost localhost>
        ServerName localhost
        DocumentRoot /var/www/
[..... lots of other stuff ....]
</VirtualHost>

<VirtualHost www.guy.guy>
        ServerName www.guy.guy
        DocumentRoot /var/www2/
[..... lots of other stuff ....]
</VirtualHost>

5) restart apache, in my case with
/etc/init.d/apache2 restart

6) now point your browser at 
http://localhost
and then at http://www.guy.guy (or whatever you called it)

Hopefully everythings now working.
Guy





More information about the gloucs mailing list