Day 26.Configuring an EC2 Instance as a Web Server with Nginx
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
- Open the AWS Console → EC2.
- Click Launch instance.
STEP 2 – Configure Instance Basics
| Setting | Value |
|---|---|
| Name | devops-ec2 |
| AMI | Ubuntu Server (20.04 LTS or 22.04 LTS) |
| Instance Type | 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
- Create a new security group or modify an existing one.
- Inbound rule:
| Type | Protocol | Port | Source |
|---|---|---|---|
| HTTP | TCP | 80 | 0.0.0.0/0 (or ::/0 for IPv6) |
- Outbound rules: Leave default (allow all).
STEP 4 – Add User Data Script
- Scroll to Advanced details → User data.
- 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
- Click Launch instance.
- Wait until the instance state is Running and status checks show 2/2 passed.
STEP 6 – Verify Nginx is Working
- Select the instance
devops-ec2. - Copy its Public IPv4 address.
- 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.