Web servers compared: nginx, Apache and Caddy
In short: A web server delivers pages and files or forwards requests to an application. The three most common on Linux are nginx, Apache and Caddy.
nginx
Fast and lean, good as a reverse proxy and for static files. The configuration is in blocks:
server {
listen 80;
server_name example.com;
location / { proxy_pass http://127.0.0.1:3000; }
}Apache (httpd)
The classic. Strengths: many modules, .htaccess files (per-folder settings without restart), very good documentation. Somewhat more resource-hungry.
Caddy
Especially simple: it obtains and renews HTTPS certificates automatically, see Let’s Encrypt and TLS certificates.
example.com {
reverse_proxy 127.0.0.1:3000
}
What is a reverse proxy?
It stands in front of the application, accepts requests (HTTPS, compression, caching, load balancing) and passes them on. The application itself does not have to care.
Choice
- Simple and automatic HTTPS: Caddy.
- Lots of traffic, reverse proxy: nginx.
- Existing software with
.htaccess(for example many PHP applications): Apache.
Always: service as its own user, current version, only needed ports open (Linux firewall).
See also: HTTP