Thursday, 19 December 2013

How to hosting multiple web sites with Apache on Linux.

Apache is the most commonly used Web Server on Linux Systems. Web Servers are used to serve Web pages requested by client computers. There are two ways to host multiple sites with one Apache Server,
and both are very simple to setup. We have the choice of using Name based virtual hosts, or IP based virtual hosts.

In most common situations we will use Name based virtual hosts, this is only requires that all the sites we wish to host point to the IP address of our Apache Server.

In my this blog i am using two web sites on one Apache Server:
      Web Sites                                     Document Root
1. www.testserver.com                     DocumentRoot /var/www/html/test
2. m.testserver.com                          DocumentRoot /var/www/html/m.test

Now open the Apache Server configuration file and add the necessary entry for the multiple virtual host.
#vi /etc/httpd/conf/httpd.conf

# <VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot /www/docs/dummy-host.example.com
# ServerName dummy-host.example.com
# ErrorLog logs/dummy-host.example.com-error_log
# CustomLog logs/dummy-host.example.com-access_log common
#</VirtualHost>

NameVirtualHost 118.112.104.111:80
        <VirtualHost 118.112.104.111:80>
         ServerAdmin sashwatkatore@testserver.com
         DocumentRoot /var/www/html/test
         ServerName www.testserver.com
#       ErrorLog logs/dummy-host.example.com-error_log
#       CustomLog logs/dummy-host.example.com-access_log common
</VirtualHost>

<VirtualHost 118.112.104.111:80>
         DocumentRoot /var/www/html/m.test
         ServerName m.testserver.com

# Other directives here
</VirtualHost>

For any query please feel free to contact me my email ID is sashwatkatore@gmail.com.

No comments:

Post a Comment