Skip to main content

Command Palette

Search for a command to run...

πŸš€ DevSecOps Journey β€” Day 19

Published
β€’3 min read
πŸš€ DevSecOps Journey β€” Day 19

Real-World NGINX Projects: Static Hosting, Reverse Proxy & Load Balancing

NGINX is one of the most widely used tools in modern infrastructure.
Today, I worked on hands-on NGINX projects that reflect real production use cases, moving beyond theory into practical implementation.

These projects helped me understand how NGINX handles traffic, routing, scalability, and fault tolerance in real systems.


πŸ”§ Installing NGINX on Ubuntu

Before starting the projects, NGINX was installed on Ubuntu:

sudo apt update
sudo apt install nginx -y

NGINX runs as a service and listens on port 80 (HTTP) by default.


🌐 Project 1: Serving a Static Website Using NGINX

πŸ”Ή Project Type: Static Web Hosting
πŸ”Ή Use Case: Hosting HTML/CSS/JS sites efficiently
πŸ”Ή GitHub Repo:
πŸ‘‰ πŸ‘‰ https://github.com/Jysh06/Nginx-Static-Website


πŸ“‚ Step 1: Place Website Files

By default, NGINX serves content from:

/var/www/html

For this project, a custom directory was used:

sudo mkdir -p /var/www/static-site
sudo cp -r * /var/www/static-site
sudo chown -R www-data:www-data /var/www/static-site

βš™οΈ Step 2: Create a Virtual Host

NGINX allows multiple websites using virtual hosts:

server {
    listen 80;
    server_name skjptpp.in;
    root /var/www/static-site;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

πŸ” Directive Breakdown

  • listen 80 β†’ Accept HTTP traffic

  • server_name β†’ Domain mapping

  • root β†’ Website directory

  • index β†’ Default file

  • try_files β†’ Safe file resolution


πŸ” Step 3: Enable & Reload

sudo ln -s /etc/nginx/sites-available/static-site /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

βœ… Static website is now live after DNS configuration.


🚨 Bonus: Custom Error Pages (404 & 500)

❌ Default NGINX Errors

  • Plain

  • Not user-friendly

βœ… Custom Error Pages

/var/www/mywebsite/
β”œβ”€β”€ 404.html
β”œβ”€β”€ 500.html
error_page 404 /404.html;
error_page 500 502 503 504 /500.html;

location = /404.html {
    root /var/www/mywebsite;
    internal;
}

location = /500.html {
    root /var/www/mywebsite;
    internal;
}

πŸ” internal ensures users can’t access error pages directly.


πŸ”„ Project 2: NGINX as a Reverse Proxy (Node.js Backend)

πŸ”Ή Project Type: Reverse Proxy + API Gateway
πŸ”Ή Use Case: Single entry point for frontend & backend
πŸ”Ή GitHub Repo:
πŸ‘‰ https://github.com/Jysh06/Nginx-node-proxy


🧠 What This Project Demonstrates

  • NGINX serving frontend static files

  • NGINX routing /api requests to Node.js backend

  • WebSocket support for real-time apps

location /api/ {
    proxy_pass http://13.201.37.133:3000;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}

▢️ Backend Setup

cd backend
npm install express cors socket.io
node index.js

This setup mirrors real API gateway patterns used in production.


βš–οΈ Project 3: NGINX as a Load Balancer

πŸ”Ή Project Type: Load Balancing
πŸ”Ή Use Case: High availability & scalability
πŸ”Ή GitHub Repo:
πŸ‘‰ https://github.com/Jysh06/Nginx-Loadbalancer


πŸ”€ Upstream Configuration

upstream backend_apis {
    least_conn;
    server 13.201.37.133:3001;
    server 13.201.37.133:3002;
}
  • least_conn β†’ Sends traffic to the least busy server

  • Improves performance during high traffic


🌐 API Routing

location /api/ {
    proxy_pass http://backend_apis;
}

🚦 Traffic Simulation

sudo apt install apache2-utils
ab -n 100 -c 10 http://skjptpp.in/api/

This helped visualize real load distribution across backends.


🎯 Why These Projects Matter in DevOps / DevSecOps

These NGINX projects covered:

  • Static content delivery

  • Reverse proxying

  • API gateway patterns

  • Load balancing strategies

  • Zero-downtime foundations

  • Real traffic simulation

All of these are core responsibilities in production DevOps environments.


βœ… Day 19 Summary

Today I built:

  • 🌐 Static website hosting with NGINX

  • πŸ”„ Reverse proxy for Node.js APIs

  • βš–οΈ Load-balanced backend services

And learned:

  • Virtual hosts & routing

  • Error handling

  • Reverse proxy headers

  • Traffic distribution strategies

This hands-on experience strengthened my understanding of how NGINX powers real-world infrastructure.