Skip to content

## πŸ“ Author

Birat Aryal β€” birataryal.github.io
Created Date: 2025-06-18
Updated Date: Wednesday 18th June 2025 10:53:05
Website - birataryal.com.np
Repository - Birat Aryal
LinkedIn - Birat Aryal
DevSecOps Engineer | System Engineer | Cyber Security Analyst | Network Engineer

🌐 What is NGINX?

NGINX is a high-performance, open-source web server and reverse proxy server, originally designed to handle large numbers of concurrent connections efficiently. Over time, it has evolved into a multifunctional web platform capable of:

  • Serving static content (HTML, CSS, JS, images)
  • Acting as a reverse proxy to forward client requests to backend servers
  • Performing load balancing across multiple upstream servers
  • Managing SSL/TLS termination for encrypted HTTPS traffic
  • Functioning as a content cache to reduce backend load
  • Serving as an API gateway or microservices router
  • Providing rate limiting, IP access control, and security header enforcement

NGINX is widely used by high-traffic websites and containerized applications due to its lightweight, fast, and event-driven architecture.


βš™οΈ Use Cases of NGINX

Here are common ways NGINX is used in real-world deployments:

  • Web Server – Serve static websites or frontend apps like React/Vue.
  • Reverse Proxy – Forward traffic to internal services running on Node.js, Python, Java, etc.
  • SSL Offloading – Handle HTTPS termination and forward traffic as HTTP to internal apps.
  • Load Balancer – Distribute requests to multiple backend servers using round-robin, IP-hash, or least connections.
  • API Gateway – Route and control microservice traffic.
  • Content Caching – Cache upstream responses to reduce latency and server load.
  • Security Gateway – Enforce access control, headers, IP restrictions, and DDoS protection.

🧩 Built-in NGINX Variables

NGINX provides many predefined variables that can be used in configuration files for logging, routing, proxying, and header manipulation.

Here’s a categorized list of the most commonly used ones:

Variable Description
$remote_addr Client IP address
$remote_port Client port
$server_addr Server IP address
$server_port Port the request was received on
$server_name Name of the server handling the request
$host Value of the Host header
$request_uri Full original request URI
$uri Current URI in request, normalized
$document_uri Same as $uri
$request Full original request line (GET /path HTTP/1.1)
$request_method HTTP method (e.g., GET, POST)
$request_body Request body (in some contexts)

πŸ“¦ Headers & Protocol

Variable Description
$http_user_agent Client user-agent string
$http_referer Referer header
$http_cookie Cookie header
$http_<header> Any client-sent header (e.g., $http_authorization)
$scheme Protocol: http or https
$server_protocol Protocol used (e.g., HTTP/1.1)

🧭 Proxying & Forwarding

Variable Description
$proxy_host Proxy target host
$proxy_add_x_forwarded_for Adds client IP to X-Forwarded-For
$upstream_addr Address of the upstream server
$upstream_response_time Time taken to get a response from upstream
$upstream_status HTTP status code from upstream

πŸ’Ύ Response & Status

Variable Description
$status Response status code
$body_bytes_sent Number of bytes sent to the client
$bytes_sent Total bytes sent to the client

πŸ•“ Time & Misc

Variable Description
$time_local Local time of request
$time_iso8601 ISO 8601 formatted time
$request_time Total time spent processing the request

πŸ“Œ Many of these variables are useful for custom log formats, conditional routing, or setting headers in reverse proxy scenarios.


πŸ“š References