Cloud Vendor | Amazon AWS |
Proficiency Level | Cloud Enthusiast |
Tags | EC2LinuxNGINXUbuntuVirtual MachineWeb Server |
Summary
In this lab, you will provision an AWS EC2 Instance (VM) that runs Ubuntu Linux server operating system. Once the instance is provisioned, you will install a NGINX Web server software on it. Once the Web server is installed, we will verify that it is running by accessing its home page with a browser. Last, we will modify the home page to show the text “Hello, computelabadmin
!”
Each exercise below builds upon the previous one. You should start each new exercise from the last step of the previous exercise unless it is explicitly written otherwise.
Learning Objectives
After completion of this lab, you will be able to:
- Provision an EC2 instance in AWS
- Connect to the newly provisioned instance using an SSH client
- Use the command line to manually install a Web server on the instance
- Connect to the Web server using a browser
- Modify the Web server’s home page
- Stop the instance
Prerequisites
To complete this lab, you will need the following:
- Reliable internet connection
- A free AWS Account used to access AWS Management Console
Exercise #1: Provision an EC2 Instance with Ubuntu Linux
In this exercise, you will provision an EC2 instance that runs Ubuntu Linux operating system.
Steps
- Sign into the AWS Management console at https://aws.amazon.com/console/ using your AWS credentials
- In the Find Services search box, type EC2 and press Enter
- On the new page, click on the
button
- On the Choose an Amazon Machine Image (AMI) screen, the
Ubuntu Server 18.04 LTS (HVM), SSD Volume Type
(Free tier eligible) AMI in the list - Select the image by clicking the
button
- On the Choose an Instance Type screen, select
General purpose t2.micro
(Free tier eligible) instance type and click on thebutton
- On the next step, Configure Instance Details, leave everything by default and click on the
button
- On the Add Storage step, leave the values as default and click on the
button
- On the next step, Add Tags, use the
and
buttons to add the following tags
Name →computelab01-ec2-i01
Role →web
Lab →computelab01
Owner →<your name>
OwnerEmail →<your email>
- Click on the
button to go to the next step
- On the Configure Security Group step, change the following:
Security group name →computelab01-ec2-sg
Security group description →Security group for my first EC2 compute lab on AWS
- Click on the
button to review the information for your EC2 instance
- Review the information for the EC2 instance and click on the
button
- In the pop-up window, change the selection to
Create a new key pair
and type the following name:
Key pair name →computelab01-ec2-keypair
- Click on the
button and save the
pem
file on your local machine
Important:Save the key in a secure location on your local machine. If you lose the key, you will not be able to connect to the machine remotely. - On the confirmation screen, click on the
button to see the list of all instances
- Milestone step: At this point, you have learned how to provision an Ubuntu Linux EC2 instance in AWS. that you have an entry with the following information in your list of EC2 instances.
Name →computelab01-ec2-i01
Instance Type →t2.micro
Instance State →running
Key Name →computelab01-ec2-keypair
Exercise #2: Connect to the newly provisioned VM using an SSH client
In this exercise, you will connect to the newly provisioned EC2 instance using an SSH client.
Steps
- Click on the
computelab01-ec2-i01
EC2 instance in the list of instances - From the Description tab on the bottom, note the IPv4 Public IP address of the instance
- Change to the folder where yousaved the
pem
file from Step 15 in Exercise #1 - Connect to the Virtual Machine via SSH by typing the following at the SSH command prompt
$ ssh -i ./computelab01-ec2-keypair.pem ubuntu@<the_ip_address_from_step_2>
- Milestone step: At this point, you have learned how to connect to the remote EC2 instance using an SSH client
Exercise #3: Use the command line to manually install a Web server on the VM
In this exercise, you will use the command line to update the Ubuntu repositories and install the NGINX Web server on the VM.
Steps
- While connected to the VM, update the Ubuntu repositories by typing the following at the command prompt
$ sudo apt-get update
Note: If asked, you have to type thecomputelabadmin
’s password because you use thesudo
command - Once the update is complete, install the NGINX web server by typing the following at the Virtual Machine command prompt
$ sudo apt-get install nginx
- Respond with
Y
(yes) to the prompts on the screen - Once the installation completes, start the NGINX web server using the following command
$ sudo /etc/init.d/nginx start
- Milestone step: At this point, you have learned how to install and start an NGINX Web server on the VM
- In AWS Management Console, on the Description tab, click on the
computelab01-ec2-sg
Security Group - Click on the Inbound tab, and then on the
button
- In the pop-up window, click on the
button and select HTTP in the Type dropdown for the new rule
- Click on the
button
- Milestone step: At this point, you have learned how to allow access to your NGINX Web server from the Internet
Exercise #4: Connect to the Web server using a browser
In this exercise, you will use a browser to connect to the Web server and load its home page.
Steps
- Open a browser on your local machine
- In the address bar, type the IP address from Step 2 in Exercise #2
- You should see the home page served by the NGINX Web server
- Milestone step: At this point, you have learned how to install and run an NGINX Web server on the remote Virtual Machine. You have also verified that you can access the web server’s home page from your local machine using a browser
Exercise #5: Modify the Web server’s home page
In this exercise, you will modify the Web server’s home page to show a custom message.
Steps
- While connected via SSH to the VM, open the HTML file that describes the NGINX home page in Vi by typing the following at the prompt
$ sudo vi /usr/share/nginx/html/index.html
Note: On some Ubuntu distributions, theindex.html
file for NGINX is in/var/www/html
. Look for file namedindex.nginx-debian.html
- Using the arrows on the keyboard, position the cursor after the exclamation mark on the line that has written the following
<h1>Welcome to nginx!</h1>
- Press the
i
key on the keyboard to enter INSERT mode in Vi - Type the following
Hello, <code>computelabadmin!</code>
- Press the
ESC
key on the keyboard to exit INSERT mode in Vi - Type the following to save the file and exit Vi
:wq
- Switch to your browser window and reload the page. You should see the updated home page
- Milestone step: At this point, you have learned how to locate the NGINX web server’s home page (also called index page) source and modify it as well as verify that the changes are visible using your local machine’s browser
Exercise #6: Stop the EC2 Instance
In this exercise, you will learn how to stop the EC2 instance and not incur any additional charges for it.
Steps
- Sign into the AWS Management Console at https://aws.amazon.com/console/ using your AWS credentials
- Click on EC2 under Recently visited services or search for EC2 in the search box
- Click on Instances in the left-side navigation
- Find and click on the
computelab01-ec2-i01
EC2 instance in the list of instances - Click on the
button and select Instance State → Stop
- In the Stop Instances pop-up confirm by clicking on the
button
- Milestone step: At this point, you have learned how to stop the EC2 instance and save on cost when you are not using it
- Sign out of the AWS Management Console
Last Update: October 4, 2019
You must be logged in to post a comment.