A Journey to the Cloud: Using Ubuntu on AWS EC2 to install NGINX

Avyana Baker
Women in Technology
4 min readDec 18, 2022

Let’s continue this journey to the cloud! I’m learning new ways to efficiently utilize Amazon Web Services (AWS) for productivity and will continue to share them with you all. In my previous article, I displayed two different ways you could launch an Amazon EC2 instance to host a webpage. This article will be quite similar, except we’re using the open source operating system (OS), Ubuntu. Also, instead of installing Apache as I’ve done in my first article, I will show how to install another popular open source web server called NGINX.

You will need:

  • An AWS IAM user account with permissions to access EC2
  • AWS Key pair — I showed how to create one here

That’s it! Now, it’s time to get started.

Step 1: Login to AWS

  • Login to your AWS IAM user account, confirm your region, and search EC2. Navigate to the left panel and click Instances.
On the EC2 Dashboard, click Instances.
  • Once you’ve clicked on Instances, you will see an orange button labeled Launch Instances. Click the button and we will configure the instance to fit our needs.
This is what the Launch Instances button looks like.

Step 2: Create the EC2 instance

  • Name the instance, choose the OS Ubuntu, and the free tier eligible instance type, t2.micro.
Example of what your screen should look like after clicking the launch instance button.
  • The instance type may be chosen already, so make sure it is specifically t2.micro.
Confirm instance type is t2.micro.
  • Choose your key pair from the drop down menu or use the button to the right to create a new key pair, if you haven’t already.
Choose your key pair name.
  • Next, comes the network settings. Click create security group, allow SSH traffic from My IP (your IP address will be listed), and allow HTTP traffic from the internet.
These are the selections to make for the network settings.
  • We will keep the default storage settings.
This is what the default storage settings will look like.
  • Go to advanced settings and scroll down to User Data.
This is where to find the user data box.
  • Copy the following command and paste into the user data box:
#!/bin/bash

#Install all available updates and nginx
apt-get update -y
apt-get install nginx -y

#Start nginx
systemctl enable nginx
systemctl start nginx

#Configure firewall to allow HTTP
ufw allow 'nginx http'
ufw enable
  • Review the summary and confirm your settings. Click launch instance.
This is what you will see in the summary section.
  • You’ve successfully created an instance that has installed NGINX!
The success message that will be received after creating an EC2 instance.

Step 3: Connect to the new EC2 instance

  • Once the EC2 instance has been successfully launched, we’ll click connect to instance, click the tab EC2 Instance Connect, then copy the Public IP address of your instance.
  • In your web browser, open a new tab, type http:// then paste your public IP address. For example:
http://3.83.201.236
  • If you’ve followed all of the steps above, then you should receive a page similar to this:
Example of web page after successfully installing NGINX.

We’re all done! Thank you for reading and following along! I hope this was helpful and I look forward to sharing more AWS projects as I continue to learn.

--

--