AWS, Cloud Computing

5 Mins Read

A Guide to Host Multiple Websites on a Single Amazon EC2 Server

Voiced by Amazon Polly


A reliable and scalable web hosting infrastructure is in high demand in today’s digital environment. Hosting several websites without sacrificing security or performance is a problem for businesses, and individuals are looking for efficient solutions. Amazon Elastic Compute Cloud (EC2), a robust and functional Amazon Web Services (AWS) service, fills this need.

Hosting numerous websites on a single Amazon EC2 server has become a common practice to maximize resource utilization and reduce operational expenses. Businesses can consolidate their web hosting requirements, streamline management, and guarantee seamless scalability to suit variable traffic volumes by allowing several websites to run on a single server instance.

This guide will show you how to set up and manage several websites on a single Amazon EC2 server, with step-by-step instructions and best practices to help you get the most out of Amazon EC2.


We are using Ubuntu for this process and Apache2 for the web server. The capacity to host several websites on a single server is one advantage of utilizing Ubuntu and Apache. This is extremely cost-effective because it lets you use a single server for all domains.

Virtual hosting is the term for this function. It runs various domains, such as and, on a single Ubuntu server’s IP address.

The virtual host for Apache points users to various folders where the domain files are stored. No matter how many virtual hosts the server manages, the client accessing the website will never know.

On your Apache server running on Ubuntu, there are no limits on how many websites you can host. Nevertheless, confirm that your server can manage the traffic and disc space. So, let’s dive into the process.

Pioneers in Cloud Consulting & Migration Services

  • Reduced infrastructural costs
  • Accelerated application deployment
Get Started

Step-by-Step Guide

Step 1:  Installing Apache web server

Firstly, install the Apache web server in your Ubuntu instance. Apache is a widely used, open-source web server software that serves web content to users upon request. For installing Apache, run the following command on your server.

You can confirm the installation by opening the IP address of your server in your browser. Copy the public IPv4 address and paste it into your browser.


When you open the IP address of your server, you should see the default Apache page, which will look like this.


Step 2: Setting up website file/directory structure

We will need to construct a directory structure to host the data for our website. Apache has a default directory structure, “/var/www” where it looks for websites. We will need to create sub-directories in this path for our domains so that the Apache server can look for them.

To do this, run the following commands in your terminal:

Step 3: Changing directory ownership

We need to change the ownership of the directories created above. The root user owns the directories created above, so we need to change their ownership to allow the currently logged user to modify the files. The web server has the appropriate permissions to access the website directories. To do that, run the following command in the terminal:

Step 4: Modifying file permission

The two directories that we previously created must be given read access. This will make the web pages accessible publicly, ensuring that our two websites are correctly served when a browser requests them.

Step 5: Create sample content for both domains

We have now set up our files and directory structure properly. Using any file editor like Vim or Nano, create a sample index.html file for each website.

Add the following text in the editor:

The same will be done for our second website.

Add the following text in the editor:

Remember to save and close each file by CTRL+X and Y, then press enter.

Step 6: Create a virtual host configuration

By setting up virtual hosts in Apache, you can host numerous websites, each with its name and content, on a single server. Follow these steps to build a virtual host setup for each website:

  • Open the Apache sites-available directory using the command:
  • Inside the configuration file, define the virtual host for your website. Here is a basic template for configuring a virtual host for “website1”:
  • ServerAdmin: Specify the email address of the website administrator.
  • DocumentRoot: Define the directory where the website files are stored.
  • ServerName: Specify the domain name of your website.
  • ServerAlias: Add any additional domain names (if applicable) that should point to this website.
  • ErrorLog and CustomLog: Configure the log file paths for error logging and access logging.

We need to repeat the same procedure for the virtual host.

Then again, add the following content to the file:

Save the file and exit.

Step 7: Enable both virtual hosts

Now that we have two configuration files for our two virtual hosts, we need to create a symbolic link and enable the configuration of the virtual hosts by the commands below:

Step 8: Restart Apache

We now need to restart our Apache web server for the changes to take effect after adding virtual hosts to our server. We can do that by the command:

Step 9: Edit your computer’s local hostfile

After following all of the above steps, you can access your virtual hosts. We need to modify the local host file on the local PC. This will make it possible for our local computer to find the right public IP address of our Amazon EC2 server with the desired content (our websites). You need to enter the public IP address of your Amazon EC2 server with the domains in the local host file so that when you enter the website domain, your browser can fetch the websites hosted in Amazon EC2 for you.

If you are running Linux, you need to edit the /etc/hosts file using the command below:

Add the below entries and save the file (assuming 1111.1111.1111.1111 as your Amazon EC2 instance public IP address).

If your local computer is running on Windows OS, open the file c:\windows\system32\drivers\etc\hosts in a text editor like notepad and enter the two items below.


Remember to replace 1111.1111.1111.1111 with the public IP of your Amazon EC2 instance.

Step 10: Test your domain in your browser

Finally, it’s time to visit your websites, and, and you should see the content we created for the virtual hosts as shown below:




Hosting several websites on a single Amazon EC2 server can be a cheap and effective way to manage many online properties. You may construct a streamlined and scalable hosting environment with the proper configuration, which includes setting the web server, creating virtual hosts, and putting in place strong security measures. You can prepare your Amazon EC2 instance to host several websites using the procedures described in this article. This guarantees your diverse web apps a seamless and safe online presence.

Drop a query if you have any questions regarding Hosting websites on Amazon EC2 server and we will get back to you quickly.

Making IT Networks Enterprise-ready – Cloud Management Services

  • Accelerated cloud migration
  • End-to-end view of the cloud environment
Get Started

About CloudThat

CloudThat is an official AWS (Amazon Web Services) Advanced Consulting Partner and Training partner, AWS Migration Partner, AWS Data and Analytics Partner, AWS DevOps Competency Partner, Amazon QuickSight Service Delivery Partner, AWS EKS Service Delivery Partner, and Microsoft Gold Partner, helping people develop knowledge of the cloud and help their businesses aim for higher goals using best-in-industry cloud computing practices and expertise. We are on a mission to build a robust cloud computing ecosystem by disseminating knowledge on technological intricacies within the cloud space. Our blogs, webinars, case studies, and white papers enable all the stakeholders in the cloud computing sphere.

To get started, go through our Consultancy page and Managed Services PackageCloudThat’s offerings.


1. Can I host unlimited websites on a single Amazon EC2 instance?

ANS: – While Amazon EC2 instances can handle multiple websites, the actual number depends on the size and traffic requirements of each website, as well as the instance’s available resources. Monitoring resource usage and considering scaling options as your hosting needs evolve is essential.

2. How can I ensure the security of my multiple websites hosted on a single Amazon EC2 server?

ANS: – Implementing robust security measures such as regularly updating software, configuring firewalls, utilizing SSL certificates, and managing user access can help enhance the security of your hosted websites.

3. What are the best practices for optimizing the performance of multiple websites on a single Amazon EC2 server?

ANS: – Optimizing performance involves implementing caching mechanisms, leveraging content delivery networks (CDNs), and fine-tuning the server configurations. Additionally, monitoring resource usage, identifying and resolving performance bottlenecks, and implementing efficient coding practices can improve website performance and user experience.

WRITTEN BY Ritushree Dutta



    Click to Comment

Get The Most Out Of Us

Our support doesn't end here. We have monthly newsletters, study guides, practice questions, and more to assist you in upgrading your cloud career. Subscribe to get them all!