Skip to main content

Command Palette

Search for a command to run...

AWS Day 26: Configuring an EC2 Instance as an Nginx Web Server Using User Data

Updated
3 min readView as Markdown
AWS Day 26: Configuring an EC2 Instance as an Nginx Web Server Using User Data
A

"I'm a 3rd-year Computer Engineering student at Marwadi University with skills in C++, web development (MERN stack), and DevOps tools like Kubernetes. I contribute to open-source projects and share tech knowledge on GitHub and LinkedIn. I'm learning cloud technologies and app deployment. As an Internshala Student Partner, I help others find jobs and courses." now currently focusing on #90DaysOfDevops

Introduction

During Day 26 of the KodeKloud 100 Days of Cloud Challenge, I learned how to automate the setup of an EC2 instance using User Data.

Instead of launching an EC2 instance and manually installing Nginx after connecting through SSH, AWS provides User Data scripts that run automatically during the first boot of the instance. This makes server provisioning faster, repeatable, and suitable for production environments.

In this lab, the objective was to launch an Ubuntu EC2 instance, automatically install Nginx using a User Data script, and make the web server accessible over HTTP.

Why Use EC2 User Data?

User Data allows you to execute shell scripts automatically when an EC2 instance starts for the first time.

Some common use cases include:

  • Installing software packages

  • Configuring web servers

  • Updating the operating system

  • Deploying applications automatically

  • Bootstrapping cloud infrastructure

Instead of performing these tasks manually after every launch, User Data automates the entire setup process.

Task Requirements

The following resources needed to be configured:

  • Launch an EC2 instance named nautilus-ec2

  • Use any available Ubuntu AMI

  • Configure a User Data script to install Nginx

  • Start and enable the Nginx service

  • Allow HTTP traffic on port 80

  • Verify that the Nginx welcome page is accessible from the internet

Step 1: Launch an EC2 Instance

I opened the EC2 Dashboard and clicked Launch Instance.

The instance was configured with the following settings:

Setting Value
Name nautilus-ec2
AMI Ubuntu
Instance Type t2.micro (default)

Step 2: Configure the User Data Script

While creating the instance, I expanded the Advanced Details section and added the following User Data script.

#!/bin/bash

apt update
apt upgrade -y
apt install nginx -y
systemctl start nginx
systemctl enable nginx

This script updates the package list, installs Nginx, starts the service, and ensures it starts automatically whenever the EC2 instance reboots.

Step 3: Configure the Security Group

Since the Nginx server needs to be accessible from the internet, I configured the Security Group to allow inbound HTTP traffic.

The inbound rule used was:

Type

Port

Source

HTTP

80

0.0.0.0/0

This allows users to access the web server using the EC2 public IP address.

Step 4: Verify the Nginx Installation

Finally, I copied the Public IPv4 address of the EC2 instance and opened it in my browser.

http://<EC2-Public-IP>

The default Nginx Welcome Page appeared successfully, confirming that the User Data script had installed and configured Nginx correctly.

Conclusion

Day 26 introduced one of the most practical automation features available in Amazon EC2.

By using a User Data script, I successfully configured an Ubuntu EC2 instance as an Nginx web server without any manual installation steps. This approach is commonly used in production environments to automate infrastructure provisioning and create consistent server deployments.

More from this blog

A

Anand Raval

122 posts

I'm Anand Raval, a Cloud & DevOps Engineer with AWS Solutions Architect Associate (SAA-C03), Certified Kubernetes Administrator (CKA), and Azure Fundamentals (AZ-900) certifications. This blog covers AWS, Kubernetes, Terraform, CI/CD, cloud architecture, automation, cost optimization, troubleshooting guides, and hands-on DevOps projects.