What is Nginx?
Nginx (pronounced "engine x") is a free, open-source program that accepts HTTP and HTTPS connections and decides what to do with them: send a file from disk, pass the request to an application, or spread it across several back-end servers. The project's own site describes it as an HTTP web server, reverse proxy, content cache, load balancer, TCP/UDP proxy server and mail proxy server. It was written by Igor Sysoev, is distributed under the 2-clause BSD licence, and commercial support is sold by F5.
In everyday hosting, "Nginx" usually means one of two set-ups. Either it serves a site on its own, with static files and PHP passed to PHP-FPM, or it sits in front of an application such as Node.js, Django or a Docker container, handling HTTPS and forwarding requests to a local port. If you are still deciding which web server to use at all, start with our guide to web servers; this page goes deeper on Nginx itself.
| Question | Answer |
|---|---|
| What it is | Web server, reverse proxy, load balancer, cache, TCP/UDP and mail proxy |
| Licence | 2-clause BSD (open source); NGINX Plus is a separate commercial product from F5 |
| Current versions | Mainline 1.31.10 and stable 1.30.8 on the nginx.org download page |
| Process model | One master process and several worker processes, event-driven |
| Main config file | nginx.conf, in /etc/nginx on most Linux packages |
| Per-folder config | None; there is no equivalent of Apache's .htaccess |
| Protocols | HTTP/1.1, HTTP/2 and HTTP/3, TLS with SNI |
How Nginx works: event-driven, not one process per connection
Older web server designs give each connection its own process or thread. Apache's prefork module works this way: one child process per connection, which is simple and isolates requests from each other, but every idle visitor holding a keep-alive connection ties up a whole process and its memory. Apache's newer event module improves on this by using threads and handing idle keep-alive connections to a listener thread, so worker threads are only used for connections with active work.
Nginx was designed around events from the start. Its beginner's guide explains the model in three parts:
- One master process reads and checks the configuration, opens the listening ports, and starts and supervises the workers. On Linux it normally runs as root so it can bind to ports 80 and 443.
- Several worker processes do the actual work. Each one runs an event loop and, using the operating system's efficient notification method (epoll on Linux, kqueue on FreeBSD and macOS), keeps thousands of connections open at once. A worker never waits on one slow client; it moves on to whichever connection has data ready. Workers run as an unprivileged user.
- The number of workers is set by
worker_processes, and the valueautomatches it to the number of CPU cores.
The practical result is low memory use under many open connections. nginx.org states that 10,000 inactive HTTP keep-alive connections take about 2.5 MB of memory. That is why Nginx is often put in front of heavier application servers: it holds the slow client connections cheaply and passes only complete requests to the back end.
The same design lets Nginx change its configuration without dropping visitors. On a reload, the master checks the new files, starts new workers with them, and tells the old workers to finish their current requests and exit.
What Nginx is used for
One Nginx install can do several of these jobs at once, often in the same server block.
| Role | What it does | Key directives |
|---|---|---|
| Web server | Serves HTML, CSS, images and downloads straight from disk | root, index, try_files |
| Reverse proxy | Accepts the visitor's request and forwards it to an app on a local port or another server | proxy_pass, proxy_set_header |
| FastCGI front end | Passes PHP requests to PHP-FPM, as in a typical WordPress or Laravel stack | fastcgi_pass |
| Load balancer | Spreads requests over a group of back-end servers, round-robin by default, or by least connections or IP hash | upstream, least_conn, ip_hash |
| Cache | Stores back-end responses on disk and serves repeat requests without touching the app | proxy_cache_path, proxy_cache |
| TLS termination | Handles HTTPS certificates and encryption so the app behind it speaks plain HTTP on localhost | listen 443 ssl, ssl_certificate |
| TCP/UDP proxy | Forwards non-HTTP traffic, such as a database or game server port | stream block |
If the term "reverse proxy" is new, our explainer on forward and reverse proxy servers covers the difference. A CDN is, in effect, many caching reverse proxies spread around the world, and several CDNs have used Nginx for exactly that.
How the Nginx configuration file is structured
Nginx is configured with directives. A simple directive is a name, its parameters and a semicolon, such as worker_processes auto;. A block directive ends in braces instead and holds other directives; blocks that can contain other directives are called contexts. The layout is always the same:
worker_processes auto; # main context
events {
worker_connections 1024;
}
http {
include mime.types;
server { # one website or app
listen 80;
server_name example.in;
location / { # which URLs this applies to
root /var/www/example;
}
}
}
A server block is Nginx's version of a virtual host. When a request arrives, Nginx compares its Host header with each block's server_name on that port. If none matches, the request goes to the default server for the port, which is the first one listed unless you mark another with default_server. Inside a server, location blocks decide how different URL paths are handled.
On Ubuntu and Debian packages, site files usually live in /etc/nginx/sites-available/ and are switched on with a symbolic link in /etc/nginx/sites-enabled/. Packages from nginx.org use /etc/nginx/conf.d/*.conf instead. Both are pulled into the http block by an include line in nginx.conf.
A minimal server block for a static site
This serves a plain HTML site from /var/www/example and returns a 404 for anything that does not exist:
server {
listen 80;
listen [::]:80;
server_name example.in www.example.in;
root /var/www/example;
index index.html;
location / {
try_files $uri $uri/ =404;
}
}
Before visitors can reach it, the domain's A and AAAA records must point at the server; our guide on pointing a domain to a VPS walks through that. Once plain HTTP works, add a certificate and a listen 443 ssl; server. The nginx.org HTTPS guide covers the ssl_certificate and ssl_certificate_key directives, and our explainer on the TLS handshake shows what happens on that connection.
A reverse proxy config for an app on a local port
Most modern apps run their own HTTP server on a local port, for example a Node.js app on 3000. Nginx faces the internet and forwards requests to it:
server {
listen 80;
server_name app.example.in;
client_max_body_size 20m;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Three details in that block matter:
- The Host header. By default Nginx does not pass the visitor's
Hostheader; it sends the name fromproxy_passinstead ($proxy_host). SettingHost $hostlets the app see the real domain, which many frameworks need for redirects and links. - HTTP/1.1 to the back end. Since version 1.29.7, Nginx uses HTTP/1.1 for proxying by default; older versions used 1.0. Distribution packages are often older than that, so the explicit
proxy_http_version 1.1;line keeps the config correct on any version. - Upload size.
client_max_body_sizedefaults to 1 MB. Larger uploads fail with a 413 Request Entity Too Large error until you raise it.
To spread traffic over two app instances, define an upstream group and point proxy_pass at it:
upstream app_pool {
least_conn;
server 127.0.0.1:3000;
server 127.0.0.1:3001;
}
# inside the server block:
# proxy_pass http://app_pool;
For a full walk-through with a process manager and HTTPS, see deploying a Node.js app on a VPS. When the app behind Nginx is down or crashes, Nginx answers with a 502 Bad Gateway page, and its error log names the upstream that failed.
Testing and reloading: nginx -t and reload
Changes in the configuration files do nothing until Nginx reloads them. The safe routine is always test, then reload:
sudo nginx -t # check syntax and referenced files
sudo systemctl reload nginx # or: sudo nginx -s reload
sudo nginx -T | less # test and print the full merged config
nginx -v # show the installed version
nginx -t checks the syntax and tries to open the files the configuration refers to, such as certificates and log paths. nginx -T does the same and prints every included file, which is the quickest way to see what Nginx is actually running. A reload sends the HUP signal to the master process; if the new configuration fails, the master rolls back and carries on with the old one. A restart, by contrast, stops Nginx first, so a broken file means downtime. Use restart only when a change needs it.
When something still goes wrong, the error log (usually /var/log/nginx/error.log) says which file and line caused it.
Nginx vs Apache vs LiteSpeed
All three serve the same websites; they differ in how they handle connections and where configuration lives. Our web server comparison covers Caddy, IIS and how to choose; this is the short version.
| Nginx | Apache HTTP Server | LiteSpeed Web Server | |
|---|---|---|---|
| Connection model | Event-driven workers | Pluggable MPMs: prefork (process per connection), worker or event (threads) | Event-driven |
Per-folder .htaccess | No | Yes | Yes, reads Apache rules |
| PHP | Through PHP-FPM | mod_php or PHP-FPM | Its own LSAPI |
| Licence | Open source (BSD) | Open source (Apache 2.0) | Commercial; OpenLiteSpeed is the open-source edition |
| Typical use | VPS sites, reverse proxy for apps, load balancing | Shared hosting, apps that ship .htaccess rules | Shared and WordPress hosting with built-in page cache |
The trade-off with Nginx is the missing .htaccess. That is a speed and security win, since Nginx does not search folders for config files on every request, but it means rewrite rules shipped with an app must be translated into the server block by someone with root access. That is one reason shared hosting tends to use Apache or LiteSpeed, and why our WordPress hosting runs on LiteSpeed with LSCache rather than Nginx.
Running Nginx on a VPS
Nginx needs root access to install and configure, so it belongs on a VPS or dedicated server rather than shared hosting. On Ubuntu the basic install is short:
sudo apt update
sudo apt install nginx
sudo ufw allow 'Nginx Full' # opens ports 80 and 443 in UFW
systemctl status nginx
Ubuntu's own package is usually a little behind the latest stable release. If you want current versions, nginx.org publishes its own apt and yum repositories for stable and mainline builds. Before installing anything, do the basic hardening in our Ubuntu VPS initial setup guide: a non-root user, key-only SSH and a firewall.
On a Bigdomainhost KVM VPS, you get full root access in Mumbai (BOM-1) or Delhi NCR (DEL-1), with Ubuntu, Debian, Rocky and AlmaLinux images. The Starter plan, at ₹674 (US$7.66) per 30-day period plus 18% GST with 2 vCPU and 4 GB RAM, is comfortably enough for Nginx in front of a small app. Remember to allow ports 80 and 443 in the server's firewall rules in the control panel as well as in UFW; the networking and firewall docs explain both.
If you would rather not manage Nginx yourself, our comparison of managed and unmanaged VPS explains what each option covers. Questions about a specific setup are welcome on WhatsApp at +91 75994 50220 at any time, by phone in IST working hours, or at support@bigdomainhost.com.
Bigdomainhost wrote this guide with AI assistance and sells the VPS hosting it mentions. Nginx behaviour, defaults and version numbers were checked against the linked nginx.org documentation on 27 November 2026.
Sources (checked )
- nginx.org: nginx: overview, features and architecture
- nginx.org: Beginner's Guide
- nginx.org: Controlling nginx (signals and reload)
- nginx.org: Command-line parameters
- nginx.org: How nginx processes a request
- nginx.org: Module ngx_http_proxy_module
- nginx.org: Using nginx as HTTP load balancer
- nginx.org: Configuring HTTPS servers
- Apache Software Foundation: Apache HTTP Server: Multi-Processing Modules (MPMs) (archived)
- LiteSpeed Technologies: LiteSpeed Web Server