What problem it solves
A browser opens https://example.org/blog/ — something on the server has to accept the connection on port 443,
decrypt TLS, read the request and answer. That’s the web server. It takes the answer from one of three places:
A file on disk
HTML, images, stylesheets, archives: /var/www/example.org/blog/index.html. The server reads the file and sends it
as is. This site works that way, as does anything built by a generator — Astro, Hugo, Jekyll.
A program next door
PHP, Python, Ruby: code builds the page. The server runs it inside itself (mod_php), hands the request to a
separate process over FastCGI (PHP-FPM), or over HTTP to an application on a neighbouring port.
Another server
The server prepares nothing itself; it forwards the request to an application — in a container, on another machine — and returns the response. Along the way it holds the shared parts: certificates, redirects, compression, limits, the log (Traefik).
In 2008 one server, usually Apache, did all three. Today the roles have split: a proxy with certificates in front, applications with their own built-in HTTP servers behind it, and nginx often sitting inside a container serving only static files. The word “web server” still covers them all.
Why it all comes down to connections
The main difference between servers is how they hold thousands of simultaneous connections. Memory use, behaviour under load and all the history below depend on it.
Apache prefork + mod_php nginx + PHP-FPM
client ──► httpd process + PHP client ─┐
client ──► httpd process + PHP client ─┤
client ──► httpd process + PHP client ─┼──► nginx worker ──► serves static itself
… client ─┤ │ (one worker per core,
client ──► httpd process + PHP client ─┘ │ thousands of connections)
▼
150 processes — client 151 waits. PHP-FPM: 5 processes,
A process with PHP inside is busy even busy only while PHP runs
while sending an image to a slow client.
Apache prefork: a process per connection
Apache with the prefork module starts a separate process for every connection. Each one carries a whole PHP
interpreter, even while it’s sending logo.png. While a client on slow mobile data downloads an image or holds
keep-alive, the process sits idle. The limit is MaxRequestWorkers (150 on Ubuntu, in
/etc/apache2/mods-available/mpm_prefork.conf): the next client waits in the queue. The 2009 Slowloris attack was
built on this: a couple hundred slow connections from one laptop tied up every process, and the site stopped
answering everyone else.
nginx: an event loop
nginx starts one worker per core (worker_processes auto), and each holds thousands of connections through
epoll: the Linux kernel itself says which connection has data, the worker handles it and moves on. A slow client
costs the worker a table entry, not a process. The per-worker limit is worker_connections, 768 on Ubuntu.
Caddy, Traefik, HAProxy and Node.js work the same way: holding 10,000 connections on one machine (named C10K back
in 1999) can only be done like this.
Apache 2.4: event
Apache 2.4 answered with the event module: idle connections are held by a separate thread, and worker threads are
busy only with requests. But mod_php doesn’t work with threads, since many PHP extensions aren’t thread-safe. So
modern Apache is event plus PHP-FPM — the same scheme as nginx.
How it changed from 2008 to 2026
2008–2010: LAMP and Apache with PHP inside
The typical server was Linux, Apache 2.2, MySQL, PHP (LAMP). PHP was built into Apache as mod_php, hosts sold
space on shared servers, and site settings lived in .htaccess — a file in the site’s directory that Apache rereads
on every request. You could edit it without root and without a restart, so everything hung on it: WordPress and
Joomla pretty URLs, redirects, directory passwords.
# /etc/apache2/sites-available/example.org.conf — Apache 2.2, as written in 2009
NameVirtualHost *:80 # required in 2.2, removed in 2.4
<VirtualHost *:80>
ServerName example.org
DocumentRoot /var/www/example.org
<Directory /var/www/example.org>
AllowOverride All # read .htaccess in every directory
Order allow,deny # 2.2 syntax; in 2.4 it's Require all granted
Allow from all
</Directory>
</VirtualHost>
# /var/www/example.org/.htaccess — WordPress pretty URLs; this file hasn't changed since
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Alongside lived IIS — for ASP.NET sites on Windows Server — and lighttpd, an event-driven server from 2003 that
served images and video while Apache built the pages. Igor Sysoev had been writing nginx for Rambler since 2002 and
opened it in 2004. By 2010 the classic layout had formed: nginx in front serves static files and holds slow
clients, Apache behind it on 127.0.0.1:8080 handles only PHP.
# nginx in front of Apache — the 2010 layout
server {
listen 80;
server_name example.org;
root /var/www/example.org;
location ~* \.(jpg|jpeg|png|gif|css|js|ico)$ {
expires 30d; # nginx serves static files; Apache never sees them
}
location / {
proxy_pass http://127.0.0.1:8080; # everything else goes to Apache with mod_php
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr; # otherwise Apache logs 127.0.0.1
}
}
In Netcraft’s January 2010 survey of the million busiest sites, Apache had 67.0%, Microsoft IIS 17.4%, nginx 4.2%. Across all sites nginx already had 11.5%, Apache 52.3%.
2010–2014: PHP-FPM, and Apache stops being needed
PHP 5.3.3 (July 2010) shipped PHP-FPM — PHP as a separate service with its own process pool, which the web server
reaches over FastCGI through a socket. “nginx in front of Apache” collapsed into “nginx + PHP-FPM”: .htaccess had
to be rewritten as location blocks, but the extra layer was gone.
# /etc/nginx/sites-available/example.org — nginx + PHP-FPM, still done this way
server {
listen 80;
server_name example.org;
root /var/www/example.org;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$args; # same as WordPress's .htaccess
}
location ~ \.php$ {
include snippets/fastcgi-php.conf; # from the nginx package on Debian and Ubuntu
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}
nginx 1.0 came out in April 2011, and Nginx, Inc. was founded the same year. Apache 2.4 (February 2012) brought the
event module and the new Require access syntax — many sites hit 403 when moving from 2.2 (see “If it doesn’t
work” below). In 2009 Ryan Dahl showed Node.js: a JavaScript application listens on a port itself and holds
connections with an event loop, like nginx. Since then Python has had Gunicorn and Uvicorn, Go has net/http in its
standard library, .NET has Kestrel. A web server in front of them is there for TLS and static files, not to run code.
2015–2019: HTTPS by default, HTTP/2 and containers
In December 2015 Let’s Encrypt opened free certificates to everyone, and the ACME protocol made getting them
automatic: certbot passes the validation itself and renews the certificate every 60 days. HTTP/2 was standardized
in May 2015 (RFC 7540): nginx learned it in 1.9.5, Apache via mod_http2 in 2.4.17, both that autumn. Browsers
enable HTTP/2 only over TLS, so HTTPS became necessary for speed too.
That’s also when servers appeared that do this on their own. Caddy (2015, in Go) obtains a certificate for any name in its config without a single line about TLS. Traefik (2016) takes routes from Docker container labels (Traefik). Docker, released in 2013, changed the question itself: services moved into containers, and the front needed a proxy that sees which of them are running right now.
In March 2019 F5 bought Nginx, Inc. for $670 million. W3Techs shares over those years: Apache went from 58.8% (January 2015) to 44.6% (January 2019), nginx from 22.9% to 40.7%.
2020–2026: CDNs in front, LiteSpeed at hosts, nginx forks
As of October 2026, W3Techs puts Cloudflare Server first at 32.4%. That isn’t a program on the site’s server: when a
site sits behind Cloudflare’s CDN, the response’s Server header says cloudflare, and what’s behind it can’t be
seen from outside.
| Server | January 2015 | January 2019 | January 2022 | October 2026 |
|---|---|---|---|---|
| Cloudflare Server | — | — | — | 32.4% |
| nginx | 22.9% | 40.7% | 33.0% | 30.3% |
| Apache | 58.8% | 44.6% | 31.3% | 21.4% |
| LiteSpeed | 2.1% | 3.7% | 11.9% | 14.0% |
| Node.js | 0.1% | 0.6% | 1.7% | 7.4% |
| Microsoft IIS | 13.3% | 9.0% | 6.2% | 2.9% |
| Caddy | — | — | — | 1.1% |
W3Techs shares are of the top 10 million sites whose server could be identified. nginx’s dip between 2019 and 2022 seems to come from W3Techs starting to count Cloudflare as a separate row. Netcraft counts differently, and its numbers can’t be compared with these directly.
What else happened:
- LiteSpeed grew at shared hosts: it reads the same
.htaccessas Apache but is event-driven, and it has its own LSCache for WordPress. The free version is OpenLiteSpeed. - HTTP/3 over QUIC (UDP 443) was standardized in 2022 (RFC 9114). In nginx since 1.25.0 (2023), on by default in Caddy; Apache has no support of its own.
- nginx forks. In 2022 former nginx developers released Angie — a compatible replacement with a statistics API and built-in ACME. In February 2024 Maxim Dounin, one of the core developers, left F5 and started freenginx over a dispute about how F5 announces vulnerabilities. nginx itself carries on: 1.30 (April 2026) brought Encrypted ClientHello, HTTP/2 to the upstream and sticky sessions; the 1.31 branch adds a forward HTTP proxy.
- Kubernetes: Ingress NGINX stopped getting updates in March 2026, and clusters are moving to the Gateway API — Envoy Gateway, Traefik, Cilium.
- NGINX Unit, F5’s application server, has been archived since October 2025 and is no longer developed.
- Cloudflare replaced nginx internally with Pingora, its own proxy in Rust, and opened the code in 2024. It’s a
library for building your own proxy, not a ready server you
apt install.
Who’s who in 2026
The alternatives are described from their documentation as of October 2026 and weren’t tested on a server for this page.
| Built on | Config | Certificates | Where you find it | |
|---|---|---|---|---|
| nginx 1.30 | C, events | server { … } and location, applied with reload without dropping connections |
separately: certbot or acme.sh | everywhere: static, proxy, PHP-FPM, inside containers |
| Apache 2.4.68 | C, processes and threads | <VirtualHost> and .htaccess in directories |
separately, certbot; there’s mod_md |
shared hosts and panels (cPanel, Plesk), old projects, .htaccess |
| Caddy 2.11 | Go, events | Caddyfile: a site in 3–4 lines |
on its own, on the first request to a name | small servers, personal projects, HTTPS without fuss |
| Traefik 3.7 | Go, events | container labels and YAML | on its own, Let’s Encrypt | Docker and Kubernetes (Traefik) |
| LiteSpeed / OpenLiteSpeed | C, events | a web panel; understands .htaccess |
in the panel | WordPress hosting |
| Angie, freenginx | C, nginx forks | like nginx | Angie has built-in ACME | where you want nginx without F5 |
| HAProxy 3.x | C, events | haproxy.cfg: frontends and backends |
ACME since 3.2 | load balancing between servers, TCP |
| Envoy | C++ | YAML or a control API | through external components | service meshes, the Gateway API in Kubernetes |
| IIS 10 | Windows | IIS Manager, web.config |
by hand or win-acme | ASP.NET on Windows Server |
Separate from this table are application servers: Node.js, Gunicorn and Uvicorn for Python, Kestrel for .NET,
net/http for Go. They answer HTTP themselves, but certificates, static files and several sites on one IP usually
aren’t left to them — something from the table goes in front.
One job, three configs
A PHP site (WordPress) over HTTPS. For nginx and Apache certbot has already put the certificate in
/etc/letsencrypt/live/example.org/; Caddy handles its own.
nginx 1.30
server {
listen 80;
server_name example.org;
return 301 https://$host$request_uri; # HTTP to HTTPS — as a separate server
}
server {
listen 443 ssl;
http2 on; # since 1.25.1; before that, listen 443 ssl http2
server_name example.org;
ssl_certificate /etc/letsencrypt/live/example.org/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/example.org/privkey.pem;
root /var/www/example.org;
index index.php;
client_max_body_size 64m; # the 1m default won't let the media library take photos
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
}
Apache 2.4 with event and PHP-FPM
# Modules: sudo a2dismod php8.3 mpm_prefork && sudo a2enmod mpm_event proxy_fcgi rewrite http2 ssl
<VirtualHost *:80>
ServerName example.org
Redirect permanent / https://example.org/
</VirtualHost>
<VirtualHost *:443>
ServerName example.org
Protocols h2 http/1.1
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.org/privkey.pem
DocumentRoot /var/www/example.org
<Directory /var/www/example.org>
AllowOverride All # WordPress's .htaccess works as is
Require all granted
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
Caddy 2.11
# /etc/caddy/Caddyfile
example.org {
root * /var/www/example.org
php_fastcgi unix//run/php/php8.3-fpm.sock # does try_files to index.php itself
file_server
}
Caddy turns on the HTTP redirect, the certificate, its renewal and HTTP/3 by itself. Five times fewer lines, but
everything Caddy does for you is something you have to know when things go wrong: where the certificate lives
(/var/lib/caddy/.local/share/caddy/), why it didn’t renew, which header it added.
Proxying to an application
A reverse proxy to an application on 127.0.0.1:3000 looks the same way. In nginx it’s location / { proxy_pass … }
plus three proxy_set_header lines so the application sees the real name, client address and scheme:
location / {
proxy_pass http://127.0.0.1:3000;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme; # without it the app thinks the request came over HTTP
}
In Caddy it’s app.example.org { reverse_proxy 127.0.0.1:3000 }, and it sets the headers itself. In Traefik, five
labels in the application’s compose file (Traefik labels).
What to pick
| If… | Use |
|---|---|
| several services in Docker on the server, coming and going | Traefik in front (Traefik), nginx inside containers where static files are needed |
| one to three sites on your own VPS, and you want HTTPS without setup | Caddy |
| static files or PHP without containers, with fine control over cache, limits, headers | nginx + certbot |
a site moving off shared hosting with lots of .htaccess and no time to rewrite it |
Apache 2.4 with event and PHP-FPM, or OpenLiteSpeed |
| many application servers behind one entry point, TCP, health checks | HAProxy |
| an application in Node, Go or Python | its own server, with a proxy in front for TLS |
| a static site without a server of your own | static hosting (Cloudflare Pages, GitHub Pages) — the web server isn’t yours |
Requirements and complexity
| Idle memory | What to learn | Until the first site | |
|---|---|---|---|
| Caddy | tens of MB, like Traefik: both are Go, and the runtime holds memory | the Caddyfile format, where it stores certificates | minutes: a package and three lines |
| nginx | single MB: a container with one placeholder page takes about 5 MB | server and location, match order, proxy_pass with and without a slash |
half an hour with certbot |
| Apache 2.4 | prefork with mod_php — tens of MB per process; event with PHP-FPM — much less |
modules and MPMs, .htaccess and AllowOverride, <Directory> order |
half an hour; more if you’re leaving prefork |
| Traefik | tens of MB: 50–90 MB with a few services and the CrowdSec plugin | entry points, routers, middleware, two kinds of config | an hour with Docker (Traefik from scratch) |
| HAProxy | single MB | frontends, backends, ACLs, timeouts | an hour, if the job is load balancing |
On a 1 GB VPS any of them fits. The bottleneck is what’s behind the server: PHP-FPM keeps at most 5 processes by
default (pm.max_children = 5 in /etc/php/8.3/fpm/pool.d/www.conf), and the sixth simultaneous PHP request waits.
location order in nginx is a common trap, so briefly: nginx first looks for an exact match (location = /), then
the longest prefix; if that prefix has ^~, it stops there. Otherwise it checks regular expressions (~, ~*) in
file order, and the first match beats the prefix. Hence the surprise: location /images/ won’t apply to
/images/a.png if there’s a location ~* \.png$ further down.
What each one gives and what it costs
| Strengths | The cost | |
|---|---|---|
| nginx | Thousands of connections per worker; reload without dropping anything: old workers finish the requests they started. More modules and examples for every case than the rest |
No .htaccess: every change takes root and a reload. Traps in location, if and proxy_pass. Certificates need a separate program. Some features (active backend health checks, the statistics API) are only in the paid NGINX Plus |
| Apache | .htaccess: a site is configured without root. Modules for everything; every CMS understands mod_rewrite. 30 years of compatibility |
.htaccess is looked up in every directory of the path on every request — extra disk hits. Prefork with mod_php eats memory. Two access syntaxes in old guides |
| Caddy | HTTPS without setup, HTTP/3 out of the box, a config of a few lines. Settings change live through the API on localhost:2019 |
Plugins only in a custom build of the binary (xcaddy build or caddy add-package), DNS providers for wildcards included. The access log is off by default; turn it on with log. Fewer guides and forum answers |
| Traefik | Routes from container labels; nothing restarts for a new service | Label errors show only in the log or the dashboard; it needs docker.sock (Traefik) |
| LiteSpeed | Reads .htaccess, runs the same sites faster than Apache thanks to events, has its own WordPress cache |
The full version is paid; OpenLiteSpeed applies rewrite rule changes from .htaccess only after a restart |
Which server answers and how to talk to it
What a site runs shows in the Server header — unless it was hidden:
curl -sI https://example.org | grep -iE '^(server|alt-svc):'
# server: nginx/1.30.4 — hide the version with server_tokens off in nginx, ServerTokens Prod in Apache
# alt-svc: h3=":443" — the server offers HTTP/3
server: cloudflare only means the site is behind the CDN. Each server has its own trio of commands — check the
config, apply without dropping connections, where the logs are:
| Check the config | Apply | Logs | |
|---|---|---|---|
| nginx | sudo nginx -t |
sudo systemctl reload nginx |
/var/log/nginx/access.log, error.log |
| Apache | sudo apachectl configtest |
sudo systemctl reload apache2 |
/var/log/apache2/ |
| Caddy | caddy validate --config /etc/caddy/Caddyfile |
sudo systemctl reload caddy |
journalctl -u caddy; the access log only with log |
| Traefik | the log at startup | dynamic — by itself; static — docker compose restart traefik |
docker logs traefik (Traefik logs) |
Put the config check before every reload: sudo nginx -t && sudo systemctl reload nginx. With a config error a
reload won’t bring nginx down — the old workers keep running — but a plain restart will.
Where to start
- Docker and several services — the Traefik overview (Traefik), then the from-scratch manual (Traefik from scratch).
- A wildcard certificate for every subdomain — Traefik and Let’s Encrypt.
- The request log and its rotation — Traefik logs; banning attackers from that log — CrowdSec with Traefik behind Cloudflare.
- Before any server — a firewall with 80 and 443 open (The ufw firewall).
If it doesn’t work
After apt install nginx it won’t start; journalctl -u nginx says bind() to 0.0.0.0:80 failed (98: Address already in use)
- Cause
- Port 80 is taken: usually by Apache, which came along with PHP (the
phppackage pulls inlibapache2-mod-phpandapache2), or by a container with a published port. - Fix
- See who holds the port:
sudo ss -ltnp 'sport = :80'. If you don’t need Apache:sudo systemctl disable --now apache2. Install PHP for nginx asphp8.3-fpm, which doesn’t pull in Apache.
502 Bad Gateway on PHP pages; /var/log/nginx/error.log says connect() to unix:/run/php/php8.3-fpm.sock failed (2: No such file or directory)
- Cause
- nginx knocks on a PHP-FPM socket that doesn’t exist: php-fpm isn’t running, or the config has a different PHP version in the path — after a system upgrade
php8.1-fpm.sockbecamephp8.3-fpm.sock. With(13: Permission denied)the socket exists but nginx’s user (www-data) can’t write to it. - Fix
ls /run/php/shows the real socket name;systemctl status php8.3-fpmshows whether it’s alive. Permissions:listen.ownerandlisten.groupin/etc/php/8.3/fpm/pool.d/www.conf,www-databy default.
Files over a megabyte won’t upload: 413 Request Entity Too Large
- Cause
- nginx’s
client_max_body_sizedefaults to1m. PHP’s limits come next:upload_max_filesizeis2M,post_max_sizeis8M. - Fix
- Put
client_max_body_size 64m;inserver { … }, thensudo nginx -t && sudo systemctl reload nginx. For PHP, raise both values in/etc/php/8.3/fpm/php.iniand restartphp8.3-fpm.
The server’s IP or someone else’s domain opens one of your sites
- Cause
- If
Hostmatches noserver_name, nginx hands the request to the default server on that port: the one markeddefault_server, or else the first in the config. With HTTPS it also shows that site’s certificate. - Fix
- Add an empty default server: on 80,
listen 80 default_server; return 444;(close the connection without a reply); on 443,listen 443 ssl default_server; ssl_reject_handshake on;(nginx 1.19.4+).
After moving to Apache 2.4 the whole site returns 403 Forbidden; the log says AH01630: client denied by server configuration
- Cause
- The config still uses 2.2 syntax:
Order allow,denyandAllow from all. In 2.4 access is set withRequire, and the old directives work only withmod_access_compat. - Fix
- Replace the pair of lines with
Require all grantedand check withsudo apachectl configtest.
WordPress on Apache: the home page opens, every other page is 404
- Cause
- Permalinks rely on
.htaccesswithmod_rewrite, and Apache doesn’t read the file:/etc/apache2/apache2.confhasAllowOverride Nonefor/var/www/, or therewritemodule isn’t enabled. - Fix
- Set
AllowOverride Allin the site’s<Directory /var/www/example.org>, enable the module withsudo a2enmod rewrite, and reload:sudo systemctl reload apache2.
The app behind nginx gets the wrong path: /api/users arrives as /users or //users
- Cause
- If
proxy_passhas a path — even just a trailing/— nginx replaces the matched part oflocationwith it.location /api/withproxy_pass http://127.0.0.1:3000/;strips/api/. - Fix
- To pass the path as is, write the address without one:
proxy_pass http://127.0.0.1:3000;. To strip a prefix, bothlocation /api/andproxy_pass …:3000/;must end with a slash.
A WebSocket through nginx won’t connect, or drops after exactly a minute
- Cause
- By default nginx talks to the app over HTTP/1.0 and doesn’t pass the
Upgradeheader. If the connection does come up,proxy_read_timeout(60s) closes it after a minute of silence. - Fix
- Add
proxy_http_version 1.1;,proxy_set_header Upgrade $http_upgrade;,proxy_set_header Connection "upgrade";to thelocationand raiseproxy_read_timeout, say to1h. Caddy and Traefik pass WebSockets through on their own.
Caddy is running, but the site shows a certificate error or doesn’t open at all
- Cause
- Caddy obtains the certificate on first start, and Let’s Encrypt validates the name through port 80 or 443. That fails if DNS still points at the old server or the firewall blocks the ports (The ufw firewall).
- Fix
dig +short example.orgshould return this server’s address;sudo ufw statusshould show 80 and 443 open. Details are injournalctl -u caddy --since 10m.