Apache Virtual Host Configuration to run Multiple Websites

Run Multiple Websites, apache virtual host examples, apache virtual host configuration centos, apache virtual host configuration, apache virtual host setup

Apache Virtual Host Configuration to run multiple websites

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.

Refer the links to know more.
Install and Configure Apache HTTP Webserver.
SSL Configuration to enable Apache HTTPS Webserver.

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.
[ads-post]
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.

Thanks for reading our post. share with your friends. We appreciate your feedback, Leave your comments if any.
We have more articles to be updated soon. To not miss any updates, Follow us on social networking sites and Subscribe us on our Youtube channel. Run Multiple Websites On A Single, virtual host in apache, apache virtual host examples, apache virtual host configuration centos, apache virtual host configuration, apache virtual host configuration file, run multiple websites apache, run multiple sites apache, host multiple websites apache, host multiple websites apache, Apache Virtual Host Configuration to run Multiple Websites
March 25, 2016

Post a Comment

[disqus][facebook][blogger]

Contact Form

Name

Email *

Message *

Powered by Blogger.
Javascript DisablePlease Enable Javascript To See All Widget