Talk to the NOC, IST hours — +91 75994 50220 support@bigdomainhost.com
Guide

What is Nginx? How it works, what it does and how to configure it

Nginx sits in front of a large share of the web, often unnoticed until a 502 page appears. This guide explains what Nginx is, why its design handles many connections cheaply, the jobs it does, and the few commands you need to configure it safely on your own server.

Short answer: Nginx (pronounced "engine x") is free, open-source software that works as a web server, reverse proxy, load balancer, content cache and TLS terminator. It uses one master process and a few event-driven worker processes, each handling thousands of connections at once, so it stays light on memory. It is commonly placed in front of PHP-FPM, Node.js or Python applications.

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.

Nginx at a glance, checked on nginx.org on 27 November 2026
QuestionAnswer
What it isWeb server, reverse proxy, load balancer, cache, TCP/UDP and mail proxy
Licence2-clause BSD (open source); NGINX Plus is a separate commercial product from F5
Current versionsMainline 1.31.10 and stable 1.30.8 on the nginx.org download page
Process modelOne master process and several worker processes, event-driven
Main config filenginx.conf, in /etc/nginx on most Linux packages
Per-folder configNone; there is no equivalent of Apache's .htaccess
ProtocolsHTTP/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 value auto matches 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.

The main roles of Nginx and the directives behind them
RoleWhat it doesKey directives
Web serverServes HTML, CSS, images and downloads straight from diskroot, index, try_files
Reverse proxyAccepts the visitor's request and forwards it to an app on a local port or another serverproxy_pass, proxy_set_header
FastCGI front endPasses PHP requests to PHP-FPM, as in a typical WordPress or Laravel stackfastcgi_pass
Load balancerSpreads requests over a group of back-end servers, round-robin by default, or by least connections or IP hashupstream, least_conn, ip_hash
CacheStores back-end responses on disk and serves repeat requests without touching the appproxy_cache_path, proxy_cache
TLS terminationHandles HTTPS certificates and encryption so the app behind it speaks plain HTTP on localhostlisten 443 ssl, ssl_certificate
TCP/UDP proxyForwards non-HTTP traffic, such as a database or game server portstream 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 Host header; it sends the name from proxy_pass instead ($proxy_host). Setting Host $host lets 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_size defaults 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 and LiteSpeed compared
NginxApache HTTP ServerLiteSpeed Web Server
Connection modelEvent-driven workersPluggable MPMs: prefork (process per connection), worker or event (threads)Event-driven
Per-folder .htaccessNoYesYes, reads Apache rules
PHPThrough PHP-FPMmod_php or PHP-FPMIts own LSAPI
LicenceOpen source (BSD)Open source (Apache 2.0)Commercial; OpenLiteSpeed is the open-source edition
Typical useVPS sites, reverse proxy for apps, load balancingShared hosting, apps that ship .htaccess rulesShared 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 )

Answers

Frequently asked questions

Still unsure? Call +91 75994 50220 or write to support@bigdomainhost.com — a human replies in IST hours.

What is Nginx used for?

Nginx is used as a web server for static files, a reverse proxy in front of applications such as Node.js, Python or PHP-FPM, a load balancer across several back-end servers, a content cache, and a TLS terminator that handles HTTPS certificates. One installation often does several of these jobs at the same time.

Is Nginx free?

Yes. Nginx is open-source software distributed under the 2-clause BSD licence, free to use on any server. F5 also sells NGINX Plus, a separate commercial edition with extra features and support, but the open-source version is what most Linux servers and tutorials use.

Why is Nginx faster than Apache with many connections?

Nginx uses a few event-driven worker processes, each handling thousands of connections without waiting on any single one. Apache's prefork model ties one process to each connection. nginx.org states 10,000 idle keep-alive connections take about 2.5 MB of memory. Apache's event MPM narrows the gap, so real speed depends on the workload.

What does nginx -t do?

nginx -t tests the configuration: it checks the syntax and tries to open files the configuration refers to, such as certificates and logs. Run it before every reload. nginx -T does the same and also prints the full merged configuration, which shows exactly what Nginx will run.

Does Nginx support .htaccess files?

No. Nginx keeps all configuration in its central files and does not read per-folder .htaccess files. Rewrite rules shipped for Apache must be translated into Nginx location and rewrite directives in the server block, which needs root access. LiteSpeed, by contrast, reads Apache .htaccess rules.

What is the difference between nginx reload and restart?

A reload makes the master process check the new configuration, start new workers with it and let old workers finish their requests, so visitors are not cut off. If the new configuration fails, Nginx keeps running the old one. A restart stops Nginx completely first, so a broken file causes downtime.

Can I run Nginx on shared hosting?

Usually not, because installing and configuring Nginx needs root access. Shared and WordPress hosting plans normally run Apache or LiteSpeed so customers can use .htaccess rules. To run Nginx with your own server blocks, use a VPS or dedicated server where you control the configuration.

Support that picks up the phone.

In IST hours, in Hindi or English, and WhatsApp replies fastest at any time. Sales, migration and emergencies all reach the same engineers. No offshore queue, no 48-hour first reply.

Need cPanel or WHM with the ports already sorted?

Web & cPanel hosting comes with cPanel ready to log in to, reseller hosting adds white-label WHM, and a KVM VPS can have cPanel & WHM pre-installed. Call +91 75994 50220 or email support@bigdomainhost.com.