DEV Community

Cover image for The Complete Guide: Deploying a Static Site on AWS using Nginx and User Data: Completely Automated
Goodness Ojonuba
Goodness Ojonuba

Posted on

The Complete Guide: Deploying a Static Site on AWS using Nginx and User Data: Completely Automated

Introduction

In this guide, you’ll learn how to deploy a static website on an AWS Ubuntu server using Nginx. Instead of manually installing Nginx and copying files each time, we’ll use EC2 user data to automate everything when the instance launches.

We’ll use the Graphite Creative template from Tooplate:
Template

📌 Project Prerequisites
Before starting, make sure you have:

  • An active AWS account
  • Basic understanding of EC2
  • A created EC2 key pair (for SSH access)
  • Security group allowing:
  • SSH (Port 22)
  • HTTP (Port 80)
  • Internet access enabled on your EC2 instance (public subnet + internet gateway)

🧠 What We’re Automating
When the EC2 instance launches, it will:

  1. Update packages
  2. Install Nginx
  3. Install wget & unzip
  4. Download the website template
  5. Extract it
  6. Move files into /var/www/html
  7. Start and enable Nginx

All automatically via User Data.

Step 1: Launch an Ubuntu EC2 Instance

  1. Go to AWS Console → EC2
  2. Click Launch Instance
  3. Choose: Ubuntu Server 24.04 LTS
  4. Select instance type: t2.micro (Free Tier eligible)
    EC2 config

  5. Select your key pair

  6. Configure Security Group:

  7. Allow HTTP (80)

  8. Allow SSH (22)

Security group

Step 2: Add This User Data Script
Scroll to Advanced Details → User Data and paste this script:

#!/bin/bash 
apt update -y 
apt install nginx -y 
apt install wget unzip -y
cd /tmp wget https://www.tooplate.com/zip-templates/2156_graphite_creative.zip 
unzip 2156_graphite_creative.zip
rm -rf /var/www/html/*
cp -r 2156_graphite_creative/* /var/www/html/
chown -R www-data:www-data /var/www/html
systemctl enable nginx 
systemctl start nginx 

Userdata

Then click Launch Instance.

Step 3: Wait for EC2 to Initialize
Give it about 3–5 minutes. wait for 2/2 or 3/3 checks
User Data runs automatically on first boot.

initializing

Step 4: Access Your Website
Go to EC2 Dashboard
Copy the Public IPv4 address

webpage

Open your browser:
http://YOUR_PUBLIC_IP
check to ensure it's http and not https in your URL.

If everything worked, your Graphite Creative site should load immediately.

webpage loaded

🎯 What Just Happened?

  • When the instance booted:
  • Ubuntu updated
  • Nginx installed
  • Website downloaded automatically using wget
  • Files extracted with unzip
  • Nginx configured and started
  • Site deployed without manual intervention That’s the power of User Data automation.

🚀 Why This Matters
This approach gives you:

  • Reproducible deployments
  • Faster provisioning
  • Zero manual configuration

This is a simple setup, but the idea behind it is powerful. Instead of treating servers like pets that need manual care, you’re starting to treat them like disposable infrastructure. If something breaks, you don’t fix it manually. You relaunch it and the automation handles the rest.

From here, you could:

  • Store your website in an S3 bucket instead of downloading it directly
  • Use Terraform to provision the EC2 instance automatically
  • Add a domain name and SSL certificate
  • Put CloudFront in front of it for better performance

But the real win here is understanding how User Data works. Once you’re comfortable with that, you can automate almost any server setup.

If you're learning cloud keep building, keep breaking things, keep pushing. Mastery comes from daily practice.

Top comments (0)