EC2 with NGINX

In this project, we will create an AWS EC2 Instance with an NGINX Webserver!

EC2’s are a great way to utilize virtual servers, and scale them according to your needs. You can use as many or as few as you need, and you can operate your server using the web-server of your choice.

Today, ours will be NGINX and we will execute this through the AWS console!

Let’s get started!

In the Console and from the Dashboard

Find “EC2” through the search bar, or under “compute” in the services menu. Choose “Instances” from the dropdown menu and hit, “Launch Instances”.

Name your EC2 Instance. Mine will be called, “NGINX”.

Then under AMI choose “Amazon Linux”.

For the “Instance Type”, we are going to go with t2.micro Free tier, but you can adjust this according to your computing needs. Then either use an existing Key pair, or create a new one. Mine is called, “launchtime”.

Next, under “Network settings” click edit and either create a security group or use an existing one. Mine is called, “WebDMZ” and it allows inbound rules for SSH (port22) and HTTP (port80).

After this, you can drop the “Advanced details” menu, and scroll to the bottom where you see, “User data”.

User data is a set of commands that you can have an instance execute upon instance launch.

Adding NGINX — User Data

#!/bin/bash
sudo yum update -y
sudo amazon-linux-extras install nginx1 -y
sudo systemctl enable nginx
sudo systemctl start nginx

These commands will update and upgrade all packages, install NGINX, and start and enable the service.

This can also be done via the Terminal after you SSH into the EC2 server.

Finally, let’s launch our instance and click, “View all instances” on the bottom right of your screen. Highlight your instance, and under the details below copy your Public IPv4 address.

Then in a new tab type, “http://your address here” and hit return.

TADA! You did it!

LAST STEP:

Make sure you terminate your EC2 instance, so that you are not charged for it’s operation.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Dane Forslund

Dane Forslund

DevOps | Cloud | AWS enthusiast. I believe my most successful moments have derived from patient leadership, proactive resolve, and often adversity.