Day 3 - AWS EC2

satyam mishrasatyam mishra
4 min read

I Installed a Web Server (NGINX) on My EC2 Instance — And Saw My First Live Page!

After finally being able to connect to my EC2 instance via SSH yesterday, I felt pumped. But now I wanted to do something real with it — something visual. I thought: “Wouldn’t it be cool if I could access this EC2 instance in a browser?”

So that’s exactly what I set out to do today:
Install a web server and host a simple page.


Step 1: Figuring Out What Web Server to Use

At first, I wasn’t sure whether to go with Apache or NGINX. Both are popular, but after a bit of Googling (and ChatGPT-ing 😅), I picked NGINX. It’s lightweight and modern — and honestly, I just wanted to see if I could get it running.


Step 2: SSH into the Instance Again

This part I had already figured out in Day 2:

ssh -i "my-key.pem" ec2-user@<EC2_PUBLIC_IP>

Once inside the terminal, I was ready to go.


Step 3: Installing NGINX

The EC2 instance was running Amazon Linux 2023, so the package manager I used was dnf.

sudo dnf install nginx -y

It took a few seconds, and then NGINX was installed!

To start the server:

sudo systemctl start nginx

To make sure it auto-starts when the instance reboots:

sudo systemctl enable nginx

Step 4: The Part I Forgot — Opening Port 80

I opened my browser, typed in the public IP of my EC2 instance, and… nothing 😐

Then it hit me — I hadn’t added HTTP (port 80) to the security group!

So I went back to the AWS console:

  • Found my EC2 instance → clicked on Security group

  • Clicked on Edit inbound rules

  • Added a rule:

    • Type: HTTP

    • Port: 80

    • Source: Anywhere (for testing)

Clicked Save, refreshed my browser, and boom 💥


Step 5: It Worked!

The default NGINX welcome page showed up!

I know it’s just a static page that says “Welcome to NGINX,” but to me, it felt like magic. That page was being served live from a virtual server I launched and configured. From scratch.

Here’s what it looked like (you can add a screenshot here if you want):


What I Learned Today

  • NGINX is easy to install, and Amazon Linux makes it pretty smooth

  • Don’t forget about security group rules — open the ports you actually want to use!

  • Seeing something work in the browser is way more satisfying than just the terminal


Bonus: I Tried Editing the Default Page

Just for fun, I edited the HTML file NGINX serves:

sudo nano /usr/share/nginx/html/index.html

I replaced the welcome message with:

<h1>Hello from my EC2 instance!</h1>

Saved the file, refreshed the browser — and boom, my custom message appeared 🎉

Day 3 (Part 2): I Switched to Apache Just to See the Difference

So earlier today, I installed NGINX on my EC2 instance and got it to serve a welcome page. It was awesome seeing something I set up actually live in the browser.

But then curiosity got the best of me…

“What if I tried Apache instead of NGINX?”


Step 1: Stopping NGINX Before Anything Else

Since NGINX was already using port 80, I had to shut it down before trying out Apache.

Here’s what I ran:

sudo systemctl stop nginx
sudo systemctl disable nginx

Didn’t want any port conflict drama.


Step 2: Installing Apache (httpd)

On Amazon Linux, Apache is available as httpd. Installing it was straightforward:

sudo dnf install httpd -y

Then I fired it up:

sudo systemctl start httpd
sudo systemctl enable httpd

And with that, Apache was running.


Step 3: Checked in the Browser (Again)

Opened the public IP of my EC2 instance in the browser, and voilà — this time, it wasn’t the NGINX page, but an “Amazon Linux Test Page.”

It felt kind of friendly — almost like Apache was welcoming me with a hug 😅


Comparing NGINX vs Apache — From a Beginner's Eyes

I wasn’t doing any performance testing. I just wanted to understand how things looked and felt:

Apache:

  • HTML served from:
    /var/www/html/index.html

  • Config files:
    /etc/httpd/

  • Service name: httpd

NGINX:

  • HTML file location:
    /usr/share/nginx/html/index.html

  • Configs:
    /etc/nginx/

  • Service name: nginx

In short: they do the same thing, but live in different folders.


Customizing Apache's Page

Just like I did with NGINX, I edited Apache’s default HTML file:

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

Replaced it with:

<h1>Hello from Apache this time!</h1>

Saved it, refreshed the browser — successss


What I Took Away from Today (Parts 1 & 2)

  • I now know how to install, start, stop, and switch between web servers

  • Apache and NGINX have different styles, but serve the same basic purpose

  • It’s okay to test both and see which one clicks with you

And most importantly — I’m starting to feel at home inside my EC2 instance.

0
Subscribe to my newsletter

Read articles from satyam mishra directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

satyam mishra
satyam mishra