DEV Community

Israel
Israel

Posted on

Configuring Nginx on an EC2 Instance.

Introduction

Hey there, today we'll be doing a quick DevOps task, setting up Nginx (A web server) on an Ubuntu server. Nothing too fancy.
If you're new welcome to my Blog, I'm Israel, a developer and DevOps Engineer looking for excitement and challenges.

The Task

The task is to set up an Ubuntu server, configure Nginx on it and have it serve a custom page as it's default page. .

The Plan

We are going to use an AWS account to provision the Ubuntu server, login to the instance via SSH, install Nginx on it then create the custom page to be displayed then finally test it to see if it works. Simple enough, let's get to it.

Musing

A big part about being a DevOps engineer is optimization. That's almost the entire thing, optimization and efficiency and continuously improving and reevaluating said process. I wrote an article about what DevOps engineers do, you can check it out at The Big Picture and if you're looking for engineers you can check out DevOps Engineers & Cloud Engineers for rockstar professionals.

1. Setting up the Ubuntu server with AWS

To do this we'll head over to AWS's Website then find your way to the console at the top right hand corner. It should look like this.

AWS Console

Now we're going to search for EC2 and launch an Ubuntu instance with settings that'll serve our purpose and cost the least, cost optimization, remember ;).

  1. Name the instance and select Ubuntu on the quick start tab
  2. Select t2.micro and create a keypair, I like to use .pem ones.
  3. Next i created a security group and allowed HTTP/HTTPS traffic from the internet and ssh traffic from my IP.
  4. create and access the server with
 ssh -i <yourkeypair.pem> ubuntu@<serveripaddress> 
Enter fullscreen mode Exit fullscreen mode

but don't forget to give execution permissions with chmod u+x keypair.pem

2. Installing and configuring Nginx

  1. Now we are in the server we can install Nginx with these commands.
    you can just run them in a script but it's advisable to first put them in one by one to get a feel of how it's done
    sudo apt update && sudo apt install -y nginx
    sudo systemctl start nginx
    sudo systemctl enable nginx

    These will install Nginx, confirm it's running and make sure it automatically runs when you restart.

  2. Navigate to the Nginx web directory with
    cd /var/www/html
    open a new index.html file with
    vi index.html
    and paste a basic html file

save and exit vim with :wq and the earlier command ensures Nginx automatically restarts and you can see changes to your site at once.

Updated page

Challenges & Contribution to learning

This was a joy to work on, taking me back to my early days when tasks like these took me more than 5 mins to work on. I had trouble deciding whether to use a domain name or not, i went with no because it just was easier.
Now i had fun writing this article and it reignited the fire i once had for writing, so now i plan to write more articles and fully commit to a writing style. Thanks HNG

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more

Top comments (0)