How to Set Up NginX on Ubuntu AWS EC2: Step-by-Step Guide

Evan Selunani
4 min readJan 31, 2025

--

This is a guide on how to set-up NginX(‘Engine X’) on Ubuntu AWS EC2. The prerequisites include the following —

  1. An AWS Account

2. Basic Knowledge of EC2 Setup

3. Basic Knowledge of Linux Commands

The Commands you need to know include—

  1. sudo — Runs the command with administrative privileges, which is required to query the status of system services.
  2. systemctl — A command-line utility for managing system services.
  3. status — Asks systemctl to display the current status of the service.
  4. Nginx — Specifies the service you want to check, in this case, the Nginx web server.
  5. Nano — A text editor, a terminal-based, user-friendly text editor.
  6. UFW — Stands for Uncomplicated Firewall, which is a user-friendly frontend for managing firewall rules in Linux.
  7. Allow — Tells the firewall to allow incoming traffic on the specified port in our case port 80.
  8. Cat — A command used to concatenate and display the contents of a file. In this case, it reads and shows the contents of /etc/os-release

Step 1: Set Up EC2 Instance.

Navigate to EC2 instance dashboard and launch the EC2 instance giving it the following key features.

  1. An AMI of Ubuntu 22.04 LTS
  2. A t2.nano instance
  3. A Keypair with .pem for SSH

Leave the other settings as default and launch your EC2 Instance.

Step 2: Verifying Ubuntu Version

To verify your Ubuntu version run the following command

cat /etc/os-release

The below is the output of the above code, showing us the version of ubuntu we are running.

Version Check.

We see that we are running Ubuntu 22.04.5 LTS (Jammy Jellyfish).

Step 3: Installing Nginx and verifying the installation.

In this step we will install Nginx, update it and verify the installation.

Run the command below to install and update nginx .

sudo apt update && sudo apt install nginx -y

The above command updates the package repository and installs Nginx in one go.

— y is a flag that automatically answers yes to the installation prompts

We can verify the installation by running the following command

nginx -v
Nginx Version

We can also verify that Nginx is running properly by running the following command.

sudo systemctl status nginx
checking the output of systemctl

The above output shows that Nginx is active and running. We can see this by the active(running) highlighted in green above.

And there you have it! We have successfully installed Nginx on our Ubuntu EC2 instance.

Step 4: Customizing the Default Page and Configure Firewall

Use the following command to create and access the default welcome page.

sudo nano /var/www/html/index.html

This opens the index.html file and allows us to edit it in Nano.

Replace the content with a custom welcome message as the one below.

<h1>Welcome to DevOps Stage 0 – Evan/@Evan Se-lunani</h1>

Finally I will configure my webserver to be accessible and allowing HTTP traffic.

To do this run the below code

sudo ufw allow 80

Navigate back to the EC2 instance dashboard page and select the security tab.

Scroll down to your security group and select it.

Selecting your security groups

Select your Inbound rules then click on edit inbound rules. On the edit inbound rules page click on add rule.

  1. For Type set it as — HTTP
  2. For Source set it as — Anywhere IPV4
  3. Add the IP as — 0.0.0.0/0

Finally click on Save rule.

Edit inbound rules

And woohooo we can access our page. Enter your EC2 instance public IP address in our browser and check if your index.html is being displayed.

You can get your EC2 Public address on the EC2 instances page under details tab.

Public IPV4 address

And below is our page!

Brave Browser

Thanks for reading through! Check out HNG for top Cloud Engineers and Solution Architects.

--

--

Evan Selunani
Evan Selunani

Written by Evan Selunani

Transforming the world, one keystroke at a time.| Certified AWS Cloud Practitioner.

No responses yet