Side by Side
| Aspect | Nginx | Apache |
|---|---|---|
| Connection model | Event loop: few workers, many connections each | Modules (MPMs): event, worker or prefork |
| Per-directory config | No; all rules in the server config | Yes, with .htaccess files |
| PHP | Through PHP-FPM | PHP-FPM, or mod_php with the prefork MPM |
| Reverse proxy | The common choice | Capable (mod_proxy) |
| Static files, many idle clients | Very light on memory | Heavier, especially with prefork |
| Typical use | New sites, apps behind a proxy, TLS in front | Shared hosting, apps that ship .htaccess rules |
How Apache Works
Apache loads a multi-processing module (MPM) that decides how requests are handled. The event MPM, the default on current Debian and Ubuntu, is efficient; prefork runs one process per connection and is needed for the old mod_php. Apache's strength is flexibility: with AllowOverride enabled it reads .htaccess files in each directory, so an application can set its own redirects and rewrite rules without touching the server configuration. That is why shared hosting runs on it, and why it checks the file system for those files on every request.
How Nginx Works
Nginx runs a few worker processes, each handling thousands of connections with an event loop. It serves static files directly and hands everything else to an application server: PHP-FPM, a Node.js or Python app, or another web server. There are no per-directory files; all rules live in the site's server block and take effect on reload. That makes it predictable and fast, at the cost of converting any .htaccess rules yourself.
Installing Either One
# Nginx sudo apt install nginx sudo nginx -t && sudo systemctl reload nginx # Apache sudo apt install apache2 sudo apachectl configtest && sudo systemctl reload apache2
Check the configuration before every reload, as above: a reload with a broken file is refused, but a restart takes the site down. Hosting a website on a VPS walks through a complete Nginx setup with HTTPS.
Which to Choose
- A new site, a static site, or an app (Node.js, Python, Go) behind a proxy: Nginx.
- A site moved from cPanel shared hosting that relies on
.htaccess: Apache, at least at first. Moving from shared hosting covers the move. - WordPress: either, with PHP-FPM. Apache if your plugins write
.htaccessrules.