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)