DEV Community

Emmanuel Mbah
Emmanuel Mbah

Posted on

Setting Up and Configuring NGINX on Ubuntu

Setting up a web server is a fundamental skill in DevOps, but doing it on Windows using WSL? Now, that was a first for me! As someone accustomed to working with traditional Linux servers, diving into WSL was both an exciting challenge and a learning experience. This blog post details my journey installing and configuring NGINX in a Windows environment using Ubuntu on WSL. The goal? To serve a custom HTML page displaying a personalized message while ensuring proper firewall rules allowed HTTP traffic. Buckle up, because this was quite the ride!

Steps Taken

Installing WSL and Ubuntu: The first step was enabling the Windows Subsystem for Linux (WSL) and installing Ubuntu:

wsl --install
Enter fullscreen mode Exit fullscreen mode

Then, I installed Ubuntu from the Microsoft Store and set it up as my default WSL distribution

Upgrading to WSL 2 and Installing the Linux Kernel Update Package: Since WSL 2 offers better performance and compatibility, I upgraded my instance

wsl --set-version Ubuntu 2
Enter fullscreen mode Exit fullscreen mode

I also downloaded and installed the Linux kernel update package from Microsoft to ensure a smooth experience.

Installing NGINX: Once inside my Ubuntu WSL environment, I updated the system packages and installed NGINX:

sudo apt update
sudo apt install nginx -y
Enter fullscreen mode Exit fullscreen mode

To confirm the installation, I checked the version:

nginx -v
Enter fullscreen mode Exit fullscreen mode

Since WSL does not use systemd, I started NGINX using:

sudo service nginx start
Enter fullscreen mode Exit fullscreen mode

Configuring the Custom HTML Page: I replaced the default NGINX page with my custom message by modifying the index.html file:

echo "Welcome to DevOps Stage 0 - [My Name]/[My SlackName]" | sudo tee /var/www/html/index.html
Enter fullscreen mode Exit fullscreen mode

Then, I restarted NGINX:

sudo service nginx restart
Enter fullscreen mode Exit fullscreen mode

Verifying the Setup: The final step was to access the webpage. Since WSL does not expose services directly to localhost, I retrieved my WSL IP using:

ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1
Enter fullscreen mode Exit fullscreen mode

I then opened http:/// (where is the response from running the command just above) in a browser and successfully saw my custom message.

Hosting on a server: After I tested and it was working fine I hosted it using AWS. That is using the EC2 with Ubuntu as my AMI (Amazon Machine Image) with mostly default settings I created a virtual server so I can share it

Major Challenges & Solutions:

  1. NGINX not starting with systemctl - Since WSL does not support systemd, I used sudo service nginx start instead.
  2. Webpage not displaying - The issue was due to WSL networking. Instead of localhost, I had to use my WSL IP address.

Learning Outcomes:

Going into this, I expected setting up NGINX on WSL to be a simple, straightforward process—spoiler alert: it wasn’t! This task gave me hands-on experience dealing with the nuances of WSL networking, systemd limitations, and firewall configurations on Windows. It reinforced my ability to troubleshoot and adapt in different environments, which is an essential skill for any DevOps professional. Plus, now I can confidently say I’ve deployed a web server on Windows using WSL! If you're aiming for a career in DevOps Engineering or Site Reliability Engineering, this type of hands-on experience is invaluable.

Top comments (0)