Linux

Setup Apache Virtual Hosts on CentOS 6.3

This shows how to setup virtual hosts on CentOS.

Configure apache

  • Configure the webserver
  • [root@webserver ~]# vim /etc/httpd/conf/httpd.conf

  • Uncomment “NameVirtualHost” (nearly at the end)
  • NameVirtualHost *:80

  • At the end, uncomment lines: (for the original host)
  • <VirtualHost *:80>
    DocumentRoot /var/www/html
    ServerName www.myserver.com
    </VirtualHost>

Create a virtual domain

  • Create a config file for the new domain
  • [root@webserver ~]# cd /etc/httpd/conf.d/
    [root@webserver ~]# vim new.conf

    <VirtualHost *:80>
    DocumentRoot /var/www/html/new
    ServerName new.myserver.com
    ServerAdmin webmaster@myserver.com
    ErrorLog logs/virtual.host-error_log
    CustomLog logs/virtual.host-access_log combined
    </VirtualHost>

Restart the webserver

  • [root@webserver ~]# service httpd restart

    Stopping httpd: [ OK ]
    Starting httpd: [ OK ]

Setup DNS / hosts file

  • Add domains to DNS
  • Add domains to hosts file for local use
  • You can add the hosts in your hosts file (/etc/hosts or C:\Windows\System32\drivers\etc\hosts)
    [root@webserver ~]# vim /etc/hosts
    Add the hosts
    192.168.1.100 new.myserver.com www.myserver.com

You have now setup a name-based virtual hosting.
Use your browser on both domains to test it.

Leave a Reply


}) _0- O-) ;) ;( :{ :o :Y :X :P :N :D :@ :? :9~ :) :(