DEV Community

Cover image for Deploying An Ubuntu Image with Nginx Server in Amazon EC2 Instance.
Joseph Igwe
Joseph Igwe

Posted on

Deploying An Ubuntu Image with Nginx Server in Amazon EC2 Instance.

Amazon EC2 instance is an Infrastruture as a Service(Iaas) in the cloud computing model. Amazon Elastic Compute provides resizeable compute capacity in the cloud. EC2 allows users to rent virtual machines, known as instances, and run applications on them.

These instances are available in various configurations, allowing users to choose the amount of virtual CPUs, memory, storage, and networking capacity that best suits their needs.

In the next few steps we will deploy an Ubuntu instance in EC2 ,and install nginx server.

PREREQUISITES:

To start ,we will need an aws account www.aws.amazon.com.
Secondly is a Webterminal,for example GitBash in this exercise.
STEPS
1 Log into your console , on the search panel above type ec2 and select it from the drop-down menu.

Select EC2 from the search pane
2 In the window that opens after step 1 , select Launch Instance.

Click and select launch instance
3 Provide a unique name for your EC2 virtual machine Hagital,in the name and Tag section.

Provide a Unique name
4 In the Application And OS Images,click on the browse more AMI and type Ubuntu in the search window.

Search for Ubuntu AMI in the task window
5 Scroll down and select "Ubuntu Server 22.04 LTS (HVM), SSD Volume Type"

Ubuntu Server22.04
6 Scroll down , in the instance type leave as default t2.micro free tier as shown .

Select t2.micro free tier
7 Scroll down to key pair login section,and select create a new key pair. We will create a key pair to grant us access when we try SSH into th machine from our web terminal.

Select create a new key pair
8 Provide a unique name for the key,and leave the remaining settings as default. Click on the create key button below. Your unique private key will download into your host machine.

Provide a unique name for your key
9 In the Networking Settings, leave default to create security group selected.Select all checkboxes to "Allow SSh from","Allow HTTPS traffic from the Internet" , and "Allow HTTP traffic from the Internet".

Leave network setting as default,select create security group and tick all the checkboxes.
10 We leave all other setting as default and click on the lauch Instance button to create the machine.
Launch Image Instance to create ec2 machine.
If suucessfully launched, we get the below message

instance created successfully

USING A WEB TERMINAL TO ACCESS THE EC2 INSTANCE AND CREATING A WEBSERVER(nginx)

1 Click the hamburger icon on the left and select Instance. Select the instance created and it opens to a new window.

Select instance from the hamburger icon to the left
2 In the new window,click and select connect

select connect
3 We can connect using EC2 instance manager,Session Manager,SSH clent or EC2 serial console. we are using SSh client to connect.Select SSH client and follow the below steps to connect.

connect to ssh client

4 Open GitBash web terminal,and locate your private key downloaded ealier in the exercise. using the commant cd

. Our is located at the download folder.

locate the private key downloaded ealier in the exercise
5 Run this command, if necessary, to ensure your key is not publicly viewable.
chmod 400 "hagital-key-pair.pem"

make the key private
6 Connect using the command below into your instance
"ssh -i "hagital-key-pair.pem" ubuntu@ec2-3-85-111-48.compute-1.amazonaws.com"

Connecting into the instance

Successfully connected into the EC2 Instance

CONFIGURE NGINX WEBSERVER
1 run the command sudo su to get admin access
2 run apt update to upgrade the instance.

Update the instance packages
3 Install Nginx using the command apt install nginx.When prompted type yes and continue.

Nginx installed successfully
4 Verify the Ip address of your machine using the command :"Ip addr"

Verify Ip Addr
5
Copy the Ip Address an paste in a browser the see your newly created webserver.

In conclusion , Amazon Ec2 is widely used for various purposes including hosting of websites,running applications,processing data and more. It forms a fundamental building block of many AWS solutions and is a vital solution.

Top comments (0)