## π 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:
π Request-Related Variables
| 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.