HNG TASK 0: Deploying a Static Website on an Nginx Web Server
Nginx is one of the most important and widely used web servers for serving website applications. It is a powerful tool that every infrastructure engineer should be proficient in.
In this documentation, I will walk you through deploying a static website on an Nginx server, which will be accessible using the server’s public IP address. For this tutorial, I have created my server using AWS.
Requirements
A Virtual Machine (VM)
SSH Access
Web Application Code
Step 1: Setting Up a Virtual Machine
In this project, I set up a virtual machine using the AWS cloud provider with the following configuration:
Instance Name: HNG
AMI: Ubuntu linux 22.4 (Free Tier)
Instance Type: t2.micro
Storage: Default 8GB gp3
Networking: Default VPC and subnet
Security Groups: Allow HTTP and SSH access from my IP
Step 2: Configuring SSH Access
While creating the instance, I configured SSH access by generating a key pair, which allows me to securely log in to the instance. I also modified the security group to allow SSH connections from all IP addresses (for testing purposes; in production, restrict this).
Step 3: Logging Into the Instance
To log into the instance, follow these steps:
Download the key file from AWS.
Move the key file to the appropriate directory and set the correct permissions:
mv keys.pem ~/.ssh/aws-new.pem chmod 400 ~/.ssh/aws-new.pem
Connect to the instance using SSH:
ssh -i ~/.ssh/aws-new.pem ec2-user@<server-ip>
Note: Replace <server-ip>
with your instance’s public IP address.
Step 4: Updating the Server and Installing Nginx
After logging into the instance, it is recommended to update the server before installing any software. To update the server and install Nginx, run the following commands:
sudo yum update -y
sudo yum install nginx -y
Step 5: Editing the Nginx Default Application Code
To customize the default Nginx page:
Navigate to the default document root:
cd /usr/share/nginx/html
Edit the
index.html
file to your preference:sudo nano index.html
Save the changes and exit the editor.
Step 6: Restarting the Nginx Server
To apply the changes, restart the Nginx server using the following commands:
sudo systemctl stop nginx
sudo systemctl start nginx
Alternatively, you can use:
sudo systemctl restart nginx
Challenges Faced and Solutions
SSH Key Permission Issues: Initially, I encountered permission errors when attempting to connect via SSH. Setting the correct permissions using
chmod 400
resolved this issue.Security Group Configuration: Allowing unrestricted SSH access posed a security risk. I learned the importance of restricting access to specific IP ranges and updated the security group accordingly.
Nginx Configuration Edits: I mistakenly edited the wrong directory initially. Double-checking the correct path helped me resolve this.
Contributions to Learning and Professional Goals
This task significantly contributed to my learning and professional development in the following ways:
1. Setting up a virtual machine on AWS reinforced my understanding of cloud infrastructure.
2. Installing, configuring, and managing Nginx enhanced my server administration skills.
3. Troubleshooting issues during the deployment process helped improve my problem-solving abilities.
Conclusion
Successfully deploying a static website on an Nginx web server was a valuable learning experience. It not only deepened my technical skills but also underscored the importance of careful planning and troubleshooting in infrastructure management.
Do you need a Devops Engineer in your company ? click here
Do you need a Site Reliabily Engineer in your company ? Click here