All guides
Term

Nginx

A high-performance HTTP server and reverse proxy utilizing an asynchronous event-driven architecture.

Nginx (pronounced "engine-x") is a high-performance, open-source HTTP server and reverse proxy utilizing an asynchronous, event-driven architecture. Originally created to solve the C10k problem of handling ten thousand concurrent connections simultaneously, it also functions as a load balancer, mail proxy, and HTTP cache. By avoiding the resource overhead of spawning new threads or processes for every request, it delivers static content and routes traffic with minimal memory usage.

How it works

Unlike traditional servers that assign a dedicated thread or process to each incoming client, Nginx uses a master-worker model. A single master process reads configuration files and manages a small, fixed pool of single-threaded worker processes—typically one per available CPU core.

Each worker operates asynchronously using non-blocking I/O multiplexing mechanisms, such as epoll on Linux or kqueue on BSD systems. When a worker receives thousands of connections, it processes events in a continuous loop without waiting for slow disk reads or network responses to finish before moving to the next request. Because it eliminates context-switching overhead, a basic configuration can hold over 10,000 inactive HTTP keep-alive connections using roughly 2.5 MB of RAM. High-traffic platforms like Netflix and Cloudflare rely on this model for edge routing and SSL termination.

Example

In production, Nginx commonly sits in front of an application server (such as Node.js, Python, or PHP-FPM) to handle TLS encryption, serve static files directly, and forward dynamic requests. Below is a minimal reverse proxy block inside /etc/nginx/sites-available/example.conf:

server {
    listen 80;
    server_name example.com;

    location /static/ {
        root /var/www/app;
        expires 30d;
    }

    location / {
        proxy_pass http://127.0.0.1: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;
    }
}

After saving changes, always validate syntax with nginx -t before applying them via systemctl reload nginx.

What matters when choosing a server or hosting

  • Traffic profile: Nginx excels at high concurrency and serving static assets, making it ideal for API gateways, microservices, and media-heavy sites. If you are weighing stack options, reviewing Nginx vs Apache: Real-World Performance Data and Benchmarks helps clarify where event-driven handling outperforms process-based models.
  • Control over configuration: Managed shared hosting rarely grants root access to edit nginx.conf. To customize caching rules, rate limiting, or FastCGI buffers, choose a VPS or dedicated server—our walkthrough on How to Install Nginx on Ubuntu: A Complete Guide covers initial setup.
  • Application integration: Because Nginx does not embed dynamic language interpreters inside worker processes, ensure your hosting stack includes fast upstream handlers like PHP-FPM or uWSGI.

Common mistakes

  • Using if inside location blocks: Nginx's if directive behaves imperatively within a declarative configuration engine, often causing unexpected routing or header bugs. Use try_files, return, or map blocks instead.
  • Omitting forwarded headers: Failing to set X-Real-IP and X-Forwarded-Proto causes backend apps to log 127.0.0.1 for every visitor and break HTTPS redirect logic.
  • Restarting instead of reloading: Running systemctl restart nginx drops active connections, whereas reload gracefully starts new workers while letting old ones finish current requests.

FAQ

Can Nginx run alongside Apache?

Yes. Many administrators place Nginx at the network edge to terminate SSL, cache responses, and serve static files while proxying dynamic requests to Apache on a local port so applications can still use .htaccess rules.

Does Nginx support .htaccess files?

No. Nginx intentionally ignores directory-level configuration files because scanning every folder path on each request degrades disk I/O performance. All rewrite and access rules live centrally in server configuration files.

How can I speed up dynamic CMS sites on Nginx?

Enabling FastCGI microcaching and tuning buffer sizes dramatically cuts database load. You can review tested directive setups in our guide on Optimized Nginx Config for WordPress: Performance and Security Data.

All glossary terms

Glossary

Related terms

Full glossary

New guides every week.

A digest of the best pieces on servers, VPN and self-hosted software. No ads, no spam.

1 email a weekOne-click unsubscribeRU · EN
Only slipjar.app articles, nothing else.