Forum Moderators: phranque
NameVirtualHost *:80
<VirtualHost 127.0.0.1 Domain1.local>
ServerName Domain1.local
DocumentRoot C:\htdocs\Domain1
DirectoryIndex index.html index.htm index.php
</VirtualHost>
<VirtualHost 127.0.0.1 phpMyAdmin>
ServerName phpMyAdmin
DocumentRoot C:\htdocs\phpMyAdmin
DirectoryIndex index.html index.htm index.php
</VirtualHost>
<VirtualHost 127.0.0.1 Domain2.local>
ServerName Domain2.local
DocumentRoot C:\htdocs\Domain2
DirectoryIndex index.html index.htm index.php
</VirtualHost>
Any help would be appreciated.
Thanks,
Bob
#-----------------------------------------------------------------
# virtual host definitions# needs to be the IP number of the network card interface
# NOT my public IP address
NameVirtualHost 10.0.0.1#-----------------------------------------------------------------
# default virtual host
<VirtualHost 10.0.0.1>
ServerName www.first-domain.net
</VirtualHost># default virtual host - www.first-domain.net
# uncomment this section to make www.first-domain.net
# a virtual server accessed locally via [first-domain...]
# and global via [first-domain.net...]<VirtualHost 10.0.0.1>
ServerName www.first-domain.net
ServerAlias first-domain
DocumentRoot /srv/www/htdocs/first-domain
</VirtualHost><Directory /srv/www/htdocs/first-domain>
DirectoryIndex index.html
Options None
# Option Indexes
Order deny,allow
Allow from all
</Directory>#-----------------------------------------------------------------
# virtual host second-domain.org.uk<Directory /srv/www/htdocs/second-domain>
DirectoryIndex index.php
Options None
# Options Indexes
Order deny,allow
Allow from all
php_admin_flag display_errors OFF
</Directory><VirtualHost 10.0.0.1>
ServerName second-domain.org.uk
ServerAlias second-domain
ServerAdmin webmaster@second-domain.org.uk
DocumentRoot /srv/www/htdocs/second-domain
</VirtualHost>#-----------------------------------------------------------------
Things to note:
(This assumes that your network card is set to the IP address of 10.0.0.1, which it probably is if you only have one card installed.)
You need to set the NameVirtualHost to the IP address of your network card - in this case 10.0.0.1
In the VirtualHost container, ServerName *must* be a live domain name that resolves to your web server's static IP address. Apache examines the header request field from external users, and from this deduces which virtual server the user wants a page from.
ServerAlias is a setting you add to your hosts file. Under Linux this is in /etc/hosts, and contains something like:
# hosts This file describes a number of hostname-to-address
# mappings for the TCP/IP subsystem. It is mostly
# used at boot time, when no name servers are running.
# On small systems, this file can be used instead of a
# "named" name server.
# Syntax:
#
# IP-Address Full-Qualified-Hostname Short-Hostname
#127.0.0.1 localhost
# special IPv6 addresses
::1 localhost ipv6-localhost ipv6-loopbackfe00::0 ipv6-localnet
ff00::0 ipv6-mcastprefix
ff02::1 ipv6-allnodes
ff02::2 ipv6-allrouters
ff02::3 ipv6-allhosts10.0.0.1 first-domain
10.0.0.1 second-domain
10.0.0.1 any-other-virtual-serveralias-here
This will then allow you to access your virtual servers from localhost, using the following in a browser:
[first-domain...]
should take you to the index.php page of the first-domain virtual server. Obviously index.php has to exist in the DocumentRoot of the hard-drive for that VirtualServer.
Just copy and paste the above examples to the end of your httd.conf file, and tweak the settings to suit your needs. Don't forget to add your ServerAlias(es) to your host file.
That's about it really. Not that difficult once you get used to it all.