DEV Community

Kemdirim Njoku
Kemdirim Njoku

Posted on

NGINX Configuration

Introduction
In this blog post, I share my experience with the DevOps Stage 0 - NGINX Configuration task. This task required me to set up and configure NGINX on a fresh Ubuntu server, serving a custom HTML page as the default page.

My Approach:
To complete this task, I followed this step-by-step approach:

Step 1: Create an AWS EC2 Instance

  1. Log in to the AWS Management Console.
  2. Navigate to the EC2 dashboard.
  3. Click "Launch Instance" and choose "Ubuntu Server 24.04 LTS (HVM), SSD Volume Type" as Amazon Machine Image .
  4. Choose the “t2.micro” instance type.
  5. Create a new key pair (I named mine “hng12” and left other options as default).
  6. Download and save the .pem file in a secure and accessible directory.
  7. Create a new security group and allow inbound SSH and HTTP traffic from all sources (0.0.0.0/0)
  8. Leave all other options as is and Launch the instance.

Step 2: Install NGINX

  1. Connect to the EC2 instance using the “EC2 Instance Connect” option.
  2. Update the package list: sudo apt update
  3. Install NGINX: sudo apt install nginx
  4. Verify NGINX installation: nginx -v

Step 3: Configure NGINX

  1. Create a new file in the /var/www/html/ directory: sudo nano /var/www/html/index.html
  2. Add the following HTML code to the file:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to DevOps Stage 0</title>
</head>
<body>
<h1>Welcome to DevOps Stage 0 - Kemdirim Njoku/Kemystery</h1>
</body>
</html>

Replace [Kemdirim Njoku] and [Kemystery] with your actual name and Slack username.

  1. Open the NGINX configuration file: sudo nano /etc/nginx/sites-available/default
  2. Confirm that the content of the configuration file is serving the custom HTML page:

`server {
listen 80;
server_name _;

root /var/www/html;
index index.html index.htm;

location / {
    try_files $uri $uri/ =404;
}
Enter fullscreen mode Exit fullscreen mode

}`

  1. Restart NGINX to apply the changes: sudo service nginx restart

Step 5: Test the Configuration

  1. Get the public IP address of the EC2 instance. In my case: 44.212.56.112
  2. Access the public IP address in a web browser: http://44.212.56.112/
  3. Verify that the custom HTML page is displayed with the correct message.

Image description

Challenges and Solutions
During this task, I encountered a few challenges:

  1. NGINX configuration: I had to learn about NGINX configuration files and how to update them to serve a custom HTML page.
  2. HTML syntax: I had to ensure that the HTML code I wrote was correct and would display the message as expected.

To overcome these challenges, I:

  1. Referenced online documentation: I consulted the official NGINX documentation and other online resources to learn about NGINX configuration files.
  2. Used online HTML validators: I used online HTML validators to ensure that my HTML code was correct and would display the message as expected.

Conclusion
Completing this task helped me gain hands-on experience with NGINX configuration and HTML syntax. I learned how to set up and configure NGINX on a fresh Ubuntu server, serving a custom HTML page as the default page.
This task contributes to my learning and professional goals by:

  1. Improving my DevOps skills: I gained experience with NGINX configuration, which is an essential skill for DevOps engineers.

  2. Enhancing my problem-solving skills: I learned how to overcome challenges and debug issues during the task.

Hire experienced DevOps Engineers here
Hire experienced Cloud Engineers here

Top comments (0)