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

  1. A Virtual Machine (VM)

  2. SSH Access

  3. 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:

  1. Download the key file from AWS.

  2. 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
    
  3. 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:

  1. Navigate to the default document root:

     cd /usr/share/nginx/html
    
  2. Edit the index.html file to your preference:

     sudo nano index.html
    
  3. 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

  1. 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.

  2. 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.

  3. 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