How to Setup Multiple Hosts on Apache
It's the example to configure virtual hostings. Following example is done as domain name[server.world (root directory[/var/www/html])], virtual domain name[virtual.host (root directory[/home/cent/public_html])]. Before doing it, it's necessarry to add new doman name in your DNS first.
- Configure httpd for Virtual Hostings.
[root@www ~]# vi /etc/httpd/conf/httpd.conf
# line 990: uncomment
NameVirtualHost *:80
# at the last lines: ( for original domain )
DocumentRoot /var/www/html
ServerName www.server.world
# at the last lines: ( for virtual domain )
DocumentRoot /home/cent/public_html
ServerName www.virtual.host
ServerAdmin [email protected]
ErrorLog logs/virtual.host-error_log
CustomLog logs/virtual.host-access_log combined
[root@www ~]# /etc/rc.d/init.d/httpd restart
Stopping httpd:[ OK ]
Starting httpd:[ OK ]
Access to the test page that is for original domain, it's OK if possible
www.yourlink.com
- Access to the test page that is for virtual domain, it's OK if possible.
[cent@www ~]$vi ./public_html/index.cgi
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
print "\n\n";
print "\n";
print "Virtual Host Test Page";
print "\n\n";
print "\n\n";
[cent@www ~]$ chmod 705 ./public_html/index.cgi