DEV Community

Cover image for How I Deployed My Ubuntu EC2 Instance with NGINX and Customized My Web Page via Command Prompt
Oluwatobiloba Oludare
Oluwatobiloba Oludare

Posted on

How I Deployed My Ubuntu EC2 Instance with NGINX and Customized My Web Page via Command Prompt

What is EC2 and Why Ubuntu?
Amazon EC2 (Elastic Compute Cloud) is a service by AWS that allows users to rent virtual machines in the cloud. These machines, called instances, can be used to run applications just like a regular computer.

I chose Ubuntu as my operating system because it's one of the most widely used Linux distributions. It's lightweight, developer-friendly, and perfect for deploying web servers like NGINX.

Step-by-Step Deployment Process

1.Login to AWS and Launch EC2 Instance

Image description

Image description

2. Change your country location to N.Virginia

Image description

3. Name your instance and Select Ubuntu Server 22.04 LTS (Free tier eligible)

Image description

4. Select t2.micro instance type (Free Tier eligible).

Image description

5. Create or select an existing key pair (.pem file).

Image description

6. As shown below, give your keypair a name and select RSA as your key pair type; seclect .pem as key file format, then click "create key pair". It will download instantly (Make sure your .pem file has the right permissions chmod 400 your-key-file.pem).

Image description

7. Configure Security Group to allow:
SSH (port 22)
HTTP (port 80)

Image description

8. Click Launch.

Image description

9. Copy your public Ipv4 address

Image description

10. Connect to the EC2 Instance via SSH
Open your command prompt or terminal, navigate to where you downloaded your key pair using "cd" (e.g. cd Downloads).
Then type this command and input your key-pair name and your public ip address - *"ssh -i your-key-file.pem ubuntu@your-ec2-public-ip" *

Image description

11. Run this command to update Ubuntu and install Nginx
sudo apt update
sudo apt install nginx

Image description

Image description

*12. To start and enable nginx run these commands: *
sudo systemctl start nginx
sudo systemctl status nginx
sudo systemctl enable nginx

Image description

Paste your public Ip address to your browser
you will see this welcome message:

Image description
🎉 You’ve successfully deployed an NGINX web server on EC2 using just your terminal!

13. To edit the welcome message to your own desire content:

14.Run this command sudo nano /var/www/html/index.nginx-debian.html. Then edit the content to your taste as shown below.

Image description

Challenges I Faced

🔐 SSH Connection Issues

I initially got a “Permission denied (publickey)” error.

This was because:

My .pem file didn’t have the right permissions.

I was using the wrong username (ec2-user instead of ubuntu for Ubuntu AMI).
**
✅ Fix: Set permission with chmod 400 and use the correct SSH username.**

Conclusion
Deploying an NGINX web server on an EC2 instance with just the command prompt was a great way to strengthen my cloud skills. It taught me the importance of networking, server setup, and command-line operations in real-world environments.

If you are just starting out with AWS or want to get comfortable managing servers via the terminal, I highly recommend trying this project. It’s simple, educational, and sets the stage for more advanced deployments.

Have you tried deploying a web server via the terminal before? Got stuck or have questions? Drop a comment below — I would love to hear your thoughts and help if I can!

Top comments (0)