This post will help you with Apache Virtual Host Configuration to run Multiple Websites.
If you are interested in learning, Request you to go through the below recommended tutorial.
DevOps Full Course Tutorial for Beginners - DevOps Free Training Online
Docker Full Course Tutorial for Beginners - Docker Free Training Online
Kubernetes Full Course Tutorial for Beginners - Kubernetes Free Training Online
Ansible Full Course Tutorial for Beginners - Ansible Free Training Online
Openstack Full Course Tutorial for Beginners - Openstack Free Training Online
This article shows you how to setup or host multiple websites on single apache webserver. Previously we have seen How to Install and Configure Apache HTTP Webserver and SSL Configuration to enable Apache HTTPS (SSL) Web server on RHEL7 / CentOS7.
Apache Virtual Host Configuration to run Multiple Websites
In Apache, there is a feature called Virtual hosting which allows us to host multiple Apache web sites on a single server. Example, if you have one big server with more than enough resources, you can host multiple websites on that single machine.
There are two types of Virtual Hosting,
1. Name-based Virtual Hosting - Multiple websites can be hosted on a single server which has SINGLE IP address.
2. IP-based Virtual Hosting - Multiple websites can be hosted on a single server which has Multiple IP Address. Each ip address will be dedicated to each websites.
1. Name-based Virtual Hosting.
Running several name-based web sites on a single IP address. For example, You want to run a web server for www.learnitguide.net and www.learnitguide.com on this single server. Your server has a single IP address 192.168.2.1, and we must have DNS names resolving to this machine IP address or make an entry in /etc/hosts file. Create a dedicated directory for each websites and keep all the web sites content on those directories respectively.
Open the main configuration file /etc/httpd/conf/httpd.conf and make the below changes at the end of the file.
<VirtualHost 192.168.2.1:80>
DocumentRoot "/www/learnitguide.net"
ServerName www.learnitguide.net
</VirtualHost>
<VirtualHost 192.168.2.1:80>
DocumentRoot "/www/learnitguide.com"
ServerName www.learnitguide.com
</VirtualHost>
Replace the website names and directory with your actual website names and directory. The asterisks refers to match all addresses.
And also we have options to run a multiple sites using different ports on a single IP address.
<VirtualHost 192.168.2.1:80>
DocumentRoot "/www/learnitguide.net"
ServerName www.learnitguide.net
</VirtualHost>
<VirtualHost 192.168.2.1:8080>
DocumentRoot "/www/learnitguide.com"
ServerName www.learnitguide.com
</VirtualHost>
2. IP-based Virtual Hosting
For example, Your server has two IP addresses (192.168.2.10 and 192.168.2.20) which resolve to the names www.learnitguide.net and www.learnitguide.com respectively.
Open the main configuration file /etc/httpd/conf/httpd.conf and make the below changes at the end of the file.
<VirtualHost 192.168.2.10>
DocumentRoot "/www/learnitguide.net"
ServerName www.learnitguide.net
</VirtualHost>
<VirtualHost 192.168.2.20>
DocumentRoot "/www/learnitguide.com"
ServerName www.learnitguide.com
</VirtualHost>
Replace the website names and directory with your actual website names and directory. The asterisks refers to match the addresses respectively.
Refer other Apache related links to know more.
Install and Configure Apache HTTP Webserver.
SSL Configuration to enable Apache HTTPS Webserver.
Keep practicing and have fun. Leave your comments if any.
Support Us: Share with your friends and groups.
Stay connected with us on social networking sites, Thank you.
apache virtual host configuration, virtual host in apache, apache virtual host examples, host multiple websites apache, host multiple websites apache
0 Comments