DEV Community

Cover image for How to Deploy Nginx on AWS EC2 using Ubuntu: A Step-by-Step Installation and Configuration Guide
Rolland Francis
Rolland Francis

Posted on • Edited on

How to Deploy Nginx on AWS EC2 using Ubuntu: A Step-by-Step Installation and Configuration Guide

WHAT IS NGINX
NGINX is a powerful web server and reverse proxy engine optimized for handling high loads, scalable web applications, and modern web architectures. It supports HTTP, HTTPS, and TCP/UDP traffic, and is often used for reverse proxying, load balancing, SSL termination, and as a microservices gateway.

What is AWS EC2?
EC2 (Elastic Compute Cloud) is a service by Amazon Web Services (AWS) that lets you rent a virtual server (called an instance). You can install anything on it, just like a computer.

🧰 To successfully deploy Nginx on a virtual server in AWS, you'll need a few things in place:
An AWS account (sign up at aws.amazon.com)

A terminal like Command Prompt, PowerShell, or Git Bash

You’ll need a terminal or shell to run commands on your local system and connect to your AWS instance.

Recommended Terminal Options:

Terminal Description
Command Prompt Built into Windows (cmd). Basic, but gets the job done.
PowerShell More powerful than cmd; supports scripting and AWS CLI well.
Git Bash Comes with Git for Windows. Provides a Linux-like terminal experience.
Windows Terminal A modern terminal from Microsoft that can combine cmd, PowerShell,

Step 1: Log In to Your AWS Account
Before you can deploy Nginx or launch any resources, you need to log in to the AWS Management Console.

How to Do It:
Go to the AWS Console:

Open your browser and visit: https://aws.amazon.com/console/

Click "Sign In to the Console"

If you already have an account, enter your:

Email address

Password

Then click "Sign In".

Once Logged In:

You’ll land on the AWS Management Console.

From here, you can search for services like EC2, S3, or IAM in the top search bar.

Step 2: Launch an EC2 Instance
An EC2 instance is a virtual server in AWS's cloud — and we'll use it to install and run Nginx.

Go to the EC2 Dashboard
In the AWS Console, type EC2 in the search bar and click the result.

You’ll land on the EC2 Dashboard.

Click “Launch Instance”
Find the “Launch instance” button and click it.

Configure Your EC2 Instance
✅ 1. Name your instance

Choose an Amazon Machine Image (AMI)
Choose: Ubuntu Server 22.04 LTS (free tier eligible)

Choose Instance Type
Select: t2.micro (Free Tier eligible)

✅ 4. Create a Key Pair
This is how you’ll securely SSH into the server.
Click Create new key pair

Name it: my-ec2-key (or anything you like)
Click Create Key Pair

It will automatically download to your computer. Keep it safe!

** Configure Network Settings**
✅ Allow SSH (port 22) — already enabled

✅ Add rule: HTTP (port 80) — required for Nginx web traffic

Storage
Default 8 GB is fine. Leave it as-is.

Launch It!
Click Launch instance

Wait a few seconds for AWS to spin up the server.

Check Your Instance
Click “View Instances”

You’ll see your new instance listed.

Wait for the Status Checks to say 2/2 checks passed

Copy the Public IPv4 address — you’ll need this to SSH into it.

Step 3: Connect to Your EC2 Instance (SSH from Windows)
This step lets you remotely access your server from your local Windows machine, using the key pair you downloaded earlier.

Option A: Using A command Prompt (Recommended for Beginners)
✅ 1. Open a Command Prompt on your computer.

✅ 2. Navigate to the directory with your command prompt

cd downloads

step 2 run the dir in Command Prompt (Windows)
dir is a command used to list all files and folders in the current directory.

Connect via SSH
Use this command (replace with your actual IP address and key filename)
ssh -i my-ec2-key.pem Ubuntu@3.886.97.457
When You’re Prompted to Proceed you may be asked to confirm if you want to continue. Then you click on yes.

Step 4: Install Nginx on Ubuntu
sudo apt install nginx -y

Next, we'll Start the NGINX server with this command.
Sudo systemctl start nginx

Then we run the second command Sudo systemctl status nginx

We are going to enable the Nginx with this command
Sudo systemctl enable nginx

Conclusion
I have successfully deployed and configured Nginx on an Ubuntu-based EC2 instance using AWS. The server is now running and accessible over the internet, serving the default Nginx web page. This setup confirms that:

The EC2 instance was launched and secured properly.

SSH access was established using a key pair.

Nginx was installed, started, and verified as active.

The firewall/security group rules allow HTTP traffic (port 80), enabling web access.

With this foundation, the server is now ready to host a custom website, act as a reverse proxy, or serve as a base for further web application deployments.

Top comments (0)