DEV Community

Cover image for Day 26.Configuring an EC2 Instance as a Web Server with Nginx
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

Day 26.Configuring an EC2 Instance as a Web Server with Nginx

Lab Information

The Nautilus DevOps Team is working on setting up a new web server for a critical application. The team lead has requested you to create an EC2 instance that will serve as a web server using Nginx. This instance will be part of the initial infrastructure setup for the Nautilus project. Ensuring that the server is correctly configured and accessible from the internet is crucial for the upcoming deployment phase.

As a member of the Nautilus DevOps Team, your task is to create an EC2 instance with the following specifications:

Instance Name: The EC2 instance must be named devops-ec2.

AMI: Use any available Ubuntu AMI to create this instance.

User Data Script: Configure the instance to run a user data script during its launch. This script should:

Install the Nginx package.
Start the Nginx service.
Enter fullscreen mode Exit fullscreen mode

Security Group: Ensure that the instance allows HTTP traffic on port 80 from the internet.

Lab Solutions

πŸ”Ή STEP 1: Launch the EC2 Instance

Go to AWS Console β†’ EC2

Click Launch instance

πŸ”Ή STEP 2: Configure Instance Basics
🏷 Name and Tags

Name: devops-ec2

🐧 AMI

Select Ubuntu Server (20.04 LTS or 22.04 LTS)

πŸ’» Instance Type

Choose t2.micro (or any allowed type)

πŸ” Key Pair

Select an existing key pair or create a new one (lab dependent)

πŸ”Ή STEP 3: Network & Security Group Configuration
Security Group (VERY IMPORTANT)

Create a new security group or modify an existing one

Add Inbound Rule:

Type Protocol Port Source
HTTP TCP 80 0.0.0.0/0
SSH (optional) TCP 22 0.0.0.0/0

Outbound rules: Leave default (allow all)

πŸ”Ή STEP 4: Add User Data Script

Scroll to Advanced details β†’ User data

Paste the following exact script:

!/bin/bash

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

βœ… This script:

Updates packages

Installs Nginx

Starts Nginx immediately

Ensures Nginx starts on reboot

πŸ”Ή STEP 5: Launch the Instance

Click Launch instance

Wait until:

Instance state: Running

Status checks: 2/2 passed

πŸ”Ή STEP 6: Verify Nginx is Working

Select the instance devops-ec2

Copy its Public IPv4 address

Open a browser and visit:

http://

βœ… Expected Output

You should see the default Nginx welcome page:

β€œWelcome to nginx!”


Resources & Next Steps
πŸ“¦ Full Code Repository: KodeKloud Learning Labs
πŸ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
πŸ’¬ Join Discussion: DEV Community - Share your thoughts and questions
πŸ’Ό Let's Connect: LinkedIn - I'd love to connect with you

Credits
β€’ All labs are from: KodeKloud
β€’ I sincerely appreciate your provision of these valuable resources.

Top comments (0)