apache tutorial - What is Virtual host in Apache - apache - apache web server - apache server - apache2



Virtual host in apache

  • An Apache web server can host multiple websites on the SAME server. You do not need separate server machine and apache software for each website. This can achieved using the concept of Virtual Host or VHost.
  • Any domain that you want to host on your web server will have a separate entry in apache configuration file.

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.
  • n 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 [email protected]

DocumentRoot /var/www/html/example1.com      

ServerName www.example1.com

</VirtualHost>

<VirtualHost 192.168.0.108:80>

ServerAdmin [email protected]

DocumentRoot /var/www/html/example2.com

ServerName www.example2.com

</VirtualHost>
click below button to copy the code. By Apache tutorial team
  • You can add as many virtual hosts, as per your requirement. You can check your web configuration files with:
[root@amsterdam ~]#httpd –t
Syntax OK
click below button to copy the code. By Apache tutorial team
  • f the configuration file has some wrong syntax, it will throw an error
[root@115 conf.d]# httpd -t

Syntax 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
click below button to copy the code. By Apache tutorial team

Related Searches to what is virtual host in apache