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

Published: (December 23, 2025 at 05:37 PM EST)
2 min read
Source: Dev.to

Source: Dev.to

Lab Information

The Nautilus DevOps Team is setting up a new web server for a critical application. Your task is 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.

Requirements

  • Instance Name: devops-ec2
  • AMI: Any available Ubuntu AMI (20.04 LTS or 22.04 LTS)
  • User Data Script: Must install Nginx, start the service, and enable it on reboot.
  • Security Group: Allow HTTP traffic on port 80 from the internet.

Steps

STEP 1 – Launch the EC2 Instance

  1. Open the AWS Console → EC2.
  2. Click Launch instance.

STEP 2 – Configure Instance Basics

SettingValue
Namedevops-ec2
AMIUbuntu Server (20.04 LTS or 22.04 LTS)
Instance Typet2.micro (or any allowed type)
Key PairSelect an existing key pair or create a new one (lab‑dependent)

STEP 3 – Network & Security Group Configuration

  1. Create a new security group or modify an existing one.
  2. Inbound rule:
TypeProtocolPortSource
HTTPTCP800.0.0.0/0 (or ::/0 for IPv6)
  1. Outbound rules: Leave default (allow all).

STEP 4 – Add User Data Script

  1. Scroll to Advanced details → User data.
  2. Paste the following 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

  1. Click Launch instance.
  2. Wait until the instance state is Running and status checks show 2/2 passed.

STEP 6 – Verify Nginx is Working

  1. Select the instance devops-ec2.
  2. Copy its Public IPv4 address.
  3. Open a web browser and visit http://.

Expected Output: The default Nginx welcome page displaying “Welcome to nginx!”.

Resources & Next Steps

  • Full Code Repository: KodeKloud Learning Labs
  • More Deep Dives: Whispering Cloud Insights – read other technical articles
  • Discussion: DEV Community – share your thoughts and questions
  • Connect: LinkedIn – feel free to connect

Credits

  • All labs are from KodeKloud.
  • Thank you for providing these valuable resources.
Back to Blog

Related posts

Read more »

Terraform Project: Simple EC2 + Security Group

Project Structure terraform-project/ │── main.tf │── variables.tf │── outputs.tf │── providers.tf │── terraform.tfvars │── modules/ │ └── ec2/ │ ├── main.tf │...

Creating EC2 Instance

Log in to the AWS Management Console - Open the AWS Management Console. - Search for EC2 in the services search bar and open the EC2 Dashboard. Launch a New In...