Use cases for Apache's ability to host and manage multiple websites (virtual hosts) on the same server. Apache is the leading HTTP web server on the Internet, and has dominated the field since 1996. Learn more about Apache's virtual hosting capabilities, and the scenarios in which virtual hosting is the best solution.
Use Case: Virtual Hosts
In the following scenarios, the user is a hosting service reseller. The user plans to host websites from many different customers, with varying rates and requirements.
Scenario 1: Hosting Multiple Sites on the Same Server
In this scenario, the user wishes to host multiple separate websites on the same server and IP address. This is a convenient way to provide web services for multiple clients, while keeping costs low.
Apache's virtual host feature allows you to host multiple websites on the same server. Each website has its own separate directory on the server. Using a few basic configuration files, Apache is able to take inbound requests for URLs and serve them from the correct directory on the server.
Scenario 2: Adding a Pointer Domain
In this scenario, the user wishes to point several different URLs to the same website.
This can be achieved in Apache by adding the "pointer" URLs to the main website's Apache configuration file. Each URL will be added as an additional ServerAlias line to the Apache configuration file, as detailed in the article Add an Apache Virtual Host on CentOS 7 and Ubuntu 16.04.
For example, to point the domains another-example.com and my-example.com to the main example.com domain, the Apache configuration file will read:
<VirtualHost *:80> ServerName example.com ServerAlias www.example.com ServerAlias another-example.com ServerAlias my-example.com DocumentRoot /var/www/example.com/html </VirtualHost>
Scenario 3: Website Testing Area
In this scenario, the user wishes to set up a testing area where a new website design can be uploaded and tested before going live. This is necessary because the website will be using PHP and MySQL. It will be much easier for the developers to work on the site on a live server, versus trying to develop the site on their local desktop computers.
The user creates a canonical domain,
test.example.com and points this domain to the web server. The user then sets up this domain as an Apache virtual host, so that it functions like a standard website.
After the website development is complete and the site is ready to go live, the user only needs to move the files from the
test.example.com directory into the
example.com directory to complete the website migration to the new design.