INTRODUCTION
This document provides a step-by-step guide on how to install and configure the NGINX web server on an Amazon EC2 Instance running on Ubuntu. At the end of this guide, we should have a functional nginx web server set up that serves a custom webpage, demonstrating foundational cloud infrastructure management and web server configuration skills.
STEP 0 - Prepping AWS
We need to set up an EC2 instance. You do that by using the search bar to search for EC2 and clicking on Launch Instance. Then follow the steps below:
- Select a free tier Ubuntu image as the AMI (Amazon Machine Image).
- Select the Instance type next, I used free tier eligible t2.micro to eliminate cost.
- Create security key pair for secure connection to your instance (ensure to keep your .pem file very safe).
- Ensure you create a security group to allow SSH connection to your instance using your .pem file.
- You can use default settings to configure instance details.
- Launch Instance.
Ensure your status check shows "2/2 checks passed" as seen in the screenshot below:
Connect to AWS EC2 Instance using code below (for SSH Client):
chmod 400 "nginx-web.pem"
(for MacOS Users only)
ssh -i "nginx-web.pem" ubuntu@ec2-44-243-195-121.us-west-2.compute.amazonaws.com
Note: nginx-web.pem should be replaced with the name of your .pem file. AWS would also assist you with commands to run as seen below:
STEP 1 - Update Package AND Install NGINX
Run the command below to update the list of packages in package manager.
sudo apt update
Run the command below to install nginx (option -y
is to automatically say yes to the permission requested during installation)
sudo apt install nginx -y
After installing the nginx service, you use the command below to start the nginx service.
sudo systemctl start nginx
The enable command below is to add nginx as part of the system services and ensure that whenever you restart your instance, the nginx service is restarted along side.
sudo systemctl enable nginx
Check the status of your nginx status to ensure it is active with below
sudo systemctl status nginx
STEP 2 - Create Your HTML File
First, we will navigate to the var directory which is the root path for your HTML files.
cd /var/www/html
Then create and write to your html file using vim with command below.
sudo vim index.html
You press "I" on your keyboard to change into insert mode and insert your code.
Press the esc key to leave insert mode and :wq to write/save and quit.
Now that your index.html file is created, restart nginx for the changes to take effect.
sudo systemctl restart nginx
STEP 3 - Update Security Group FOR EC2 Instance
Under the Security tab of the EC2 Instance, Click on the security group.
Edit inbound rules and add rule to allow port 80 to enable us access the HTML page over the internet.
You can now open your web browser and verify via the public IP as seen in the screenshot below.
Access the html page through your web browser.
http://your-server-ip
Project Completed.
Top comments (0)