Containerized Web Hosting: A Guide to Deploying Multiple Websites with Docker, Nginx, and AWS Route 53 Subdomain Redirection

4 min readDec 26, 2023


In today’s digital landscape, containerization has become a popular approach for deploying and managing applications. Docker, a leading containerization platform, allows developers to package applications and their dependencies into containers for seamless deployment. In this blog post, we will explore a use case where two different dummy websites are deployed using Docker containers and Nginx, with domain management facilitated by AWS Route 53.


Before we dive into the details, ensure you have the following prerequisites:

  1. Docker installed on your server or local machine.
  2. Nginx is installed on your server or local machine and configured to act as a reverse proxy.
  3. AWS Route 53 account with the domain “” registered.

Step 1: Launching AWS EC2 Ubuntu 22.04 instance

Begin by creating an AWS EC2 instance (I have created an Ubuntu 22.04 EC2 instance).

Step 2: Docker and Nginx installation on AWS EC2 Ubuntu instance

#Linux commands to install the nginx and docker
apt update
apt install -y nginx

#download the script to setup the docker engine
curl -fsSL -o
sudo sh

Once nginx and docker are installed verify them:

systemctl status nginx.service
systemctl status docker.service

#We need to add the user to the docker group
sudo usermod -aG docker $USER

Step 3: Setting up Docker Containers:

Creating two Docker containers for your dummy websites. For this example, let’s call them Container “nginx-abc” and “nginx-def”. You can use any web application or static content inside these containers.

# Commands to create Docker containers "nginx-abc" and "nginx-def"
docker run -d --name nginx-abc -p 8080:80 nginx
docker run -d --name nginx-def -p 8081:80 nginx

Step 4: Configuring Nginx for Subdomain Redirection:

Now, set up Nginx as a reverse proxy to redirect traffic based on subdomains. Create a configuration file, e.g., "abc.conf" and “def.conf”, and configure the server blocks.

Note: I have used my domain name “”, so replace your domain name with my domain name.

#Restart Nginx Server
sudo systemctl restart nginx

Step 5: Access the containers and cat the “index.html” file

I have connected with both of the containers and cat the “index.html” file to show you the content of the page.

Step 6: Configuring AWS Route 53:

I have created subdomains “” and “”. Define the A records to the destination IP address of our AWS EC2 instance machine.

Step 7: Final step verification


Congratulations! You have successfully deployed two Docker containers with Nginx as a reverse proxy, redirecting traffic from subdomains “” and “” AWS Route 53 plays a crucial role in managing the domain and directing traffic to the appropriate IP addresses. This setup allows for a scalable and organized approach to hosting multiple websites on a single domain.

I hope you enjoyed reading this article, please feel free to contact me Syedusmanahmad if you have any questions.

Please feel free to write @ | Linkedin for any queries on AWS/DevOps & stay tuned for the next write-up.

If this post was helpful, please click the clap 👏 button below a few times to show your support for the author 👇




AWS & DevOps Architect | Linux, Docker, Kubernetes, Terraform, Jenkins, Git&GitHub, Ansible expert