In this article we will see about setting up virtual hosts on apache. Virtual host helps us to run multiple web sites on a single server.
There are 2 types of virtual hosting in Apache,
Types of Virtual hosts:
Name-based virtual hosting.
IP-based virtual hosting.
Name-based virtual hosting:
Name-based virtual hosting allows you to run more domains under a single IP. The conf directory for virtual host is/usr/local/apache-2.4.37/conf/extra/httpd-vhost.conf
Now we have setup two virtual host using name-based virtual hosting,
The * match all addresses, so the main server serves no requests, 80 is the default port for httpd, so all the request are handled by http.
ServerAdmin - The email address for the admin of the host. DocumentRoot - The document path where the web files of the host are maintained ServerName - The host name. ServerAlias - An alias for your host name. ErrorLog - Path for the error logs written. CustomLog - Path for the access logs written.
To enable virtual host the following things should be verified on httpd.conf file,
The above line should be uncommented on httpd.conf to enable the vhost module.
Including the vhost conf file,
We can maintain the virtual host on the httpd.conf itself since we are going to maintain virtual hosts on default conf we need to include them on the httpd.conf.
Include conf/extra/httpd-vhosts.conf
Uncomment the above line on httpd.conf to the include the file.
IP-based virtual hosting:
IP based virtual hosting comes when you want to run your host on different IP on the same server, This also allows you to set multiple domains if you are having multiple interfaces on your server.
On the above vhost file you are running two virtual hosts on different IP 192.54.67.10 and 192.54.67.11.
Do not forget to test your configuration through -t command before starting the apache process.
Thats it, now you are running virtual hosts on your system.
Comments