Sunday, 24 March 2013

Name Based Virtual Domain in Apache on Centos

If you want to run multiple Website in Single IP Address. This is achieved using DNS Server. In DNS Server we will point manivel.com and manivel-test.com to same IP Address.Then you can configure Name Based Virtual Domain in Apache Web Server.

How to Configure Name Based Virtual Domain

First you need to install HTTPD  then open apache configuration file you need to Add ,command and uncommand some line


[root@iitb-st ~]# vim /etc/httpd/conf/httpd.conf

          #Listen 12.34.56.78:80
           Listen  80

         #ServerAdmin root@localhost
    
         DocumentRoot "/var/www/html"

         # Use name-based virtual hosting.
         #

          NameVirtualHost 10.107.91.51:80

        ##### Virtual domain    #################
  
     <VirtualHost 10.107.91.51:80>
          ServerAdmin  manivel@manivel.com
          DocumentRoot  /var/www/html/site1
          ServerName  manivel.com
          ServerAlias   www.manivel.com
          ErrorLog logs/manivel.com-error_log
          CustomLog logs/manivel.com-access_log common
     </VirtualHost>


     <VirtualHost 10.107.91.51:80>
          ServerAdmin  manivel@manivel.com
          DocumentRoot  /var/www/html/site2
          ServerName  manivel-test.com
          ServerAlias   www.manivel-test.com
          ErrorLog logs/manivel-test.com-error_log
          CustomLog logs/manivel-test.com-access_log common
    </VirtualHost> 

Now Restart the service 

          [root@iitb-st ~]#  /etc/init.d/httpd   restart

If you want to Verrify Virtual Configuration syntax using "httpd  -S"

          [root@iitb-st ~]# httpd -S

If you want to verrify Apache Configuration file syntax using  "httpd  -t"

           [root@iitb-st ~]# httpd -t

   To create additional virtual host you can just repeat the above process.

I hope this helps...

No comments:

Post a Comment