Loading....
Lab
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

  1. Sign into the AWS Management console at https://aws.amazon.com/console/ using your AWS credentials
  2. In the Find Services search box, type EC2 and press Enter
  3. On the new page, click on the button
  4. On the Choose an Amazon Machine Image (AMI) screen, find the Ubuntu Server 18.04 LTS (HVM), SSD Volume Type (Free tier eligible) AMI in the list
  5. Select the image by clicking the button
  6. On the Choose an Instance Type screen, select General purpose t2.micro (Free tier eligible) instance type and click on the button
  7. On the next step, Configure Instance Details, leave everything by default and click on the button
  8. On the Add Storage step, leave the values as default and click on the button
  9. On the next step, Add Tags, use the and buttons to add the following tags
    Namecomputelab01-ec2-i01
    Roleweb
    Labcomputelab01
    Owner<your name>
    OwnerEmail<your email>
  10. Click on the button to go to the next step
  11. On the Configure Security Group step, change the following:
    Security group namecomputelab01-ec2-sg
    Security group description
    Security group for my first EC2 compute lab on AWS
  12. Click on the button to review the information for your EC2 instance
  13. Review the information for the EC2 instance and click on the button
  14. In the pop-up window, change the selection to
    Create a new key pairand type the following name:
    Key pair namecomputelab01-ec2-keypair
  15. 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.
  16. On the confirmation screen, click on the button to see the list of all instances
  17.  Milestone step:  At this point, you have learned how to provision an Ubuntu Linux EC2 instance in AWS. Verify that you have an entry with the following information in your list of EC2 instances.
    Namecomputelab01-ec2-i01
    Instance Typet2.micro
    Instance Staterunning
    Key Namecomputelab01-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.

Note: You need to have an SSH client installed on your machine. If you run MacOS or Linux, the SSH client is available by default. If you run Windows 10, you need to enable it from the Programs and Features in your Settings. For other Windows versions, you will need to download third-party SSH client software.

Steps

  1. Click on the computelab01-ec2-i01 EC2 instance in the list of instances
  2. From the Description tab on the bottom, note the IPv4 Public IP address of the instance
  3. Change to the folder where yousaved the pem file from Step 15 in Exercise #1
  4. 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>
  5.  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

  1. 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 the computelabadmin’s password because you use the sudo command
  2. 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
  3. Respond with Y (yes) to the prompts on the screen
  4. Once the installation completes, start the NGINX web server using the following command
    $ sudo /etc/init.d/nginx start
  5.  Milestone step:  At this point, you have learned how to install and start an NGINX Web server on the VM
  6. In AWS Management Console, on the Description tab, click on the computelab01-ec2-sg Security Group
  7. Click on the Inbound tab, and then on the button
  8. In the pop-up window, click on the button and select HTTP in the Type dropdown for the new rule
  9. Click on the button
  10.  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

  1. Open a browser on your local machine
  2. In the address bar, type the IP address from Step 2 in Exercise #2
  3. You should see the home page served by the NGINX Web server
  4.  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

  1. 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, the index.html file for NGINX is in /var/www/html. Look for file named index.nginx-debian.html
  2. 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>
  3. Press the i key on the keyboard to enter INSERT mode in Vi
  4. Type the following
    Hello, <code>computelabadmin!</code>
  5. Press the ESC key on the keyboard to exit INSERT mode in Vi
  6. Type the following to save the file and exit Vi
    :wq
  7. Switch to your browser window and reload the page. You should see the updated home page
  8.  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

  1. Sign into the AWS Management Console at https://aws.amazon.com/console/ using your AWS credentials
  2. Click on EC2 under Recently visited services or search for EC2 in the search box
  3. Click on Instances in the left-side navigation
  4. Find and click on the computelab01-ec2-i01 EC2 instance in the list of instances
  5. Click on the button and select Instance StateStop
  6. In the Stop Instances pop-up confirm by clicking on the button
  7.  Milestone step:  At this point, you have learned how to stop the EC2 instance and save on cost when you are not using it
  8. Sign out of the AWS Management Console

Last Update: October 4, 2019  

September 22, 2019   323   Toddy Mladenov    Compute    
Total 0 Votes:
0

Tell us how can we improve this post?

+ = Verify Human or Spambot ?

Back To Top