Deploy static website on AWS EC2 using Nginx – tutorial featured image

How to Deploy Static Website on AWS EC2 Using Nginx?

Want to deploy a static website on AWS EC2 using Nginx in under 15 minutes? This guide will show you exactly how to do that with zẻo cost using AWS Free Tier.

Learn more about Amazon EC2 and Nginx web server if you’re new to these tools.

What is Amazon EC2?

Amazon EC2 (Elastic Compute Cloud) is Amazon’s cloud-based virtual server service. It allows you to run applications or host data without having to invest in physical hardware.

Tip: You can use the AWS Free Tier to follow this guide at zero cost, which includes 750 hours per month of t2.micro instances.

What is Nginx?

Nginx is a high-performance open-source web server known for its ability to handle thousands of concurrent connections while consuming minimal resources. It’s commonly used to serve static content, act as a reverse proxy, or load balancer.

Step-by-Step Deployment

1. Launch an EC2 Instance

  • Select operating system: Ubuntu (latest version)
  • Instance type: t2.micro
  • Create a Key Pair for SSH access (.pem file)

Connect to your EC2 instance from your local machine. If you’re using Windows, you can use a terminal tool like MobaXterm.

2. Install Nginx to Serve Your Static Website

Run the following commands:

sudo apt update
sudo apt install nginx -y

Start the Nginx service:

sudo systemctl start nginx

3. Create a Static HTML File

Use Vim or any text editor to create index.html:

vim index.html
Screenshot of MobaXterm connecting to EC2 via SSH

Press i to start typing.

Screenshot of creating index.html file using Vim
Here’s a sample content:
<!DOCTYPE html>
<html>
<head>
    <title>My Static Page</title>
</head>
<body>
    <h1>Welcome to My Website!</h1>
</body>
</html>

To save the file: press Esc, then type :wq and hit Enter.

Screenshot showing how to save an HTML file in Vim

4. Move the HTML File to Nginx’s Default Directory

sudo mv index.html /var/www/html/

5. Test and Reload Nginx Configuration

sudo nginx -t
sudo systemctl reload nginx

6. Allow HTTP Access via Security Group

  1. Go to EC2 Console → Select your Instance
  2. Navigate to Security > Security groups
AWS EC2 interface showing Security Group tab

3. Click Edit inbound rules

Terminal showing steps to deploy a static website on EC2 with Nginx

4. Add a rule: HTTP | Port: 80 | Source: 0.0.0.0/0

Adding an HTTP rule (port 80) in EC2 Security Group
Successful Nginx reload after config change

5. Click Save rules

Nginx config test passed message on terminal

7. Access the Website

Open your browser and visit the Public IP of your EC2 instance. You should see your static HTML page rendered.

Static HTML website accessed via EC2 public IP

Conclusion

📚 Useful resources:

By following this guide, you’ve successfully launched an EC2 server, installed Nginx, and deployed a static HTML website. This is a great starting point for anyone getting familiar with cloud services.

Try expanding your HTML project, or integrate it with technologies like Node.js, Docker, or CI/CD pipelines for more professional deployments.

—–

Contact us for direct advice and the fastest quote.

☎ Hotline: +84868865738

🌐 Website: https://slitigenz.io/

📩 Email: welcome@slitigenz.io

en_USEnglish