Forem

Cover image for My Experience Setting Up NGINX on an Ubuntu Server in AWS - HNG DevOps
cycy
cycy

Posted on

My Experience Setting Up NGINX on an Ubuntu Server in AWS - HNG DevOps

Introduction

As part of my DevOps Stage 0 assignment, I was tasked with setting up an NGINX web server on a fresh Ubuntu server hosted on AWS. The goal was to configure NGINX to serve a custom HTML page with a specific message and document my experience in a blog post. While this task was relatively basic, it served as an excellent refresher on foundational DevOps practices and cloud infrastructure management. Below, I’ll share my approach, insights, and reflections on how this task contributes to my professional growth.


Approach to Completing the Task

The task involved several key steps, each of which reinforced my understanding of cloud infrastructure and web server configuration. Here’s how I approached it:

  1. Setting Up the AWS Environment:

    • I launched an Ubuntu EC2 instance using AWS’s default VPC and a public subnet. This ensured that the server had internet access and could be reached via SSH and HTTP.
    • I configured the security group to allow SSH (port 22) and HTTP (port 80) traffic, ensuring secure yet accessible connectivity.
  2. Connecting to the EC2 Instance:

    • Using the .pem key pair generated during instance creation, I connected to the server via SSH. This step reminded me of the importance of secure key management and the role of SSH in remote server administration.
  3. Installing and Configuring NGINX:

    • I updated the package list and installed NGINX using apt, Ubuntu’s package manager. This step highlighted the simplicity of package management in Linux-based systems.
    • After installation, I verified that NGINX was running and enabled it to start on boot. This ensured the web server would remain operational even after a system reboot.
  4. Creating a Custom HTML Page:

    • I replaced the default NGINX landing page with a custom HTML file located at /var/www/html/index.html. The file contained the message: “Welcome to DevOps Stage 0 - [Your Name]/[SlackName].”
    • This step reinforced my understanding of how web servers serve static content and the importance of file permissions and directory structures.
  5. Testing the Configuration:

    • I accessed the server’s public IP address in a web browser and confirmed that the custom HTML page was displayed correctly. This step validated that the server was properly configured and accessible over the internet.

Insights Gained

While this task was straightforward, it provided valuable insights and served as a good refresher on several key concepts:

  1. Cloud Infrastructure Basics:

    • Launching an EC2 instance and configuring security groups reminded me of the foundational principles of cloud computing, such as virtualization, networking, and security.
  2. Linux Server Administration:

    • Working with Ubuntu reinforced my familiarity with Linux commands, package management, and file system navigation. These skills are essential for any DevOps engineer.
  3. Web Server Configuration:

    • Installing and configuring NGINX deepened my understanding of how web servers operate and how to serve static content. It also highlighted the importance of ensuring services are running and accessible.
  4. Automation Potential:

    • While I performed these steps manually, I recognized how tools like Ansible, Terraform, or AWS CloudFormation could automate this process, saving time and reducing human error.

Challenges and Solutions

Fortunately, I did not encounter any significant challenges during this task. However, I can imagine a few potential issues and how to address them:

  1. SSH Connection Issues:

    • If you’re unable to connect to your EC2 instance, ensure that:
      • The security group allows SSH traffic from your IP.
      • The .pem file has the correct permissions (chmod 400 your-key.pem).
      • The instance has a public IP assigned.
  2. NGINX Not Starting:

    • If NGINX fails to start, check the logs for errors:
     sudo systemctl status nginx
     sudo journalctl -xe
    
  • Common issues include port conflicts or misconfigurations in the NGINX configuration files.
  1. Custom HTML Page Not Displaying:

    • Ensure the index.html file is in the correct directory (/var/www/html) and has the appropriate permissions:
     sudo chown www-data:www-data /var/www/html/index.html
     sudo chmod 644 /var/www/html/index.html
    

Personal Growth and Professional Relevance

This task, though basic, aligns with my broader professional goals and contributes to my growth in several ways:

  1. Foundational DevOps Skills:

    • Setting up a web server is a fundamental DevOps task. It reinforces the importance of understanding infrastructure as code, configuration management, and deployment pipelines.
  2. Cloud Proficiency:

    • Working with AWS EC2 and VPCs enhances my cloud computing skills, which are critical for modern DevOps roles. It also prepares me for more advanced tasks like load balancing, auto-scaling, and multi-region deployments.
  3. Problem-Solving Mindset:

    • Even though I didn’t face challenges this time, the task encouraged me to think critically about potential issues and their solutions. This mindset is invaluable in real-world DevOps scenarios.
  4. Preparation for Advanced Tasks:

    • This task lays the groundwork for more complex projects, such as deploying dynamic web applications, setting up CI/CD pipelines, or configuring monitoring and logging for web servers.
  5. Career Alignment:

    • As I aspire to become a DevOps engineer, tasks like this align with the skills required for roles such as DevOps Engineers and Cloud Engineers. They also prepare me for certifications like AWS Certified Solutions Architect or Certified Kubernetes Administrator.

Conclusion

Completing this NGINX configuration task was a rewarding experience that reinforced my foundational knowledge of cloud infrastructure, Linux administration, and web server configuration. While the task was relatively simple, it served as a reminder of the importance of mastering the basics before tackling more complex challenges. As I continue my DevOps journey, I look forward to building on this foundation and exploring more advanced topics like automation, containerization, and orchestration.


References

  1. DevOps Engineers - HNG Tech
  2. Cloud Engineers - HNG Tech

Top comments (0)