Types of Apache Virtualhost
- Name-based Virtual host
- Address-based or IP based virtual host and.
Name-based Virtual Host
Name based virtual hosting is used to host multiple virtual sites on a single IP address.
In order to configure name based virtual hosting, you have to set the IP address on which you are going to receive the Apache requests for all the desired websites. You can do this by NameVirutalHost directive within the apache configuration i.e. httpd.conf/apache2.conf file.
Apache virtual host Example:
NameVirtualHost *:80<VirtualHost 192.168.0.108:80>ServerAdmin webmaster@example1.comDocumentRoot /var/www/html/example1.comServerName www.example1.com </VirtualHost>ServerAdmin admin@example2.com<VirtualHost 192.168.0.108:80> DocumentRoot /var/www/html/example2.com</VirtualHost>ServerName www.example2.com
You can add as many virtual hosts, as per your requirement. You can check your web configuration files with:
[root@amsterdam ~]#httpd –tSyntax OK
If the configuration file has some wrong syntax, it will throw an error
[root@115 conf.d]# httpd -tSyntax error on line 978 of /etc/httpd/conf/httpd.conf:Invalid command '*', perhaps misspelled or defined by a module not included in the server configuration
IP-based Virtual host
In order to setup IP based virtual hosting, you need more than one IP address configured on your server. So, the number of vhost apache will depend onnumber of IP address configured on your server. If your server has 10 IP addresses, you can create 10 IP based virtual hosts.
In the above diagram two websites example1.com and example2.com were assigned different IPs and are using IP-based virtual hosting.
Listen 192.168.0.100:80<VirtualHost 192.168.10.108:80>ServerAdmin webmaster@example1.comDocumentRoot /var/www/html/example1.comServerName www.example1.com </VirtualHost>ServerAdmin admin@example2.com<VirtualHost 192.168.10.109:80> DocumentRoot /var/www/html/example2.com</VirtualHost>ServerName www.example2.com
Post a Comment