Apache guide
What Apache does in production
Apache listens on ports (typically 80 and 443), matches each request to a
virtual host, and either serves files from disk or forwards
the request to a backend via mod_proxy. Access control, URL
rewriting, TLS termination, and compression are handled by loadable
modules. On SadServers scenarios you debug real configs:
wrong Listen ports, broken vhosts, missing modules, and
permission errors on log or document directories.
How a request is handled
When a client connects, the typical workflow is:
- TCP accept — Apache receives the connection on a
Listenport - TLS handshake — if HTTPS,
mod_sslnegotiates the certificate (vhost selected by SNI) - Virtual host match — Apache picks a
<VirtualHost>usingServerName,ServerAlias, and port - URL mapping —
DocumentRoot,Alias,ProxyPass, or rewrite rules determine the handler - Access check —
Requiredirectives allow or deny the request - Response — static file, CGI, or proxied backend response; logged to
access_log/error_log
If no vhost matches, the first vhost for that port is used as the default — a common source of "wrong site" bugs.
Configuration layout
Paths differ by distribution:
- Debian/Ubuntu —
/etc/apache2/apache2.conf, sites insites-available//sites-enabled/, modules viaa2enmod/a2dismod - RHEL/CentOS/Rocky —
/etc/httpd/conf/httpd.conf, vhosts inconf.d/, modules inmodules/
Always run a syntax check before reload:
apache2ctl configtest (Debian) or httpd -t (RHEL).
Key concepts to know
- Virtual hosts —
ServerName/ServerAliasmatching against the Host header - Modules —
LoadModule,a2enmod proxy, MPM choice (prefork, worker, event) - Logs —
ErrorLogfor failures;CustomLogfor access; check these first - Reverse proxy —
ProxyPass/ProxyPassReverseto app servers (Gunicorn, Node, etc.) - systemd —
apache2orhttpdunit; reload does not drop existing connections - .htaccess — per-directory overrides (if
AllowOverridepermits); slower than vhost config
Learning resources
- Apache HTTP Server documentation — httpd.apache.org/docs/2.4 (official 2.4 reference)
- Virtual hosts — httpd.apache.org/docs/2.4/vhosts (name-based vhost guide)
- mod_proxy — httpd.apache.org/docs/2.4/mod/mod_proxy (reverse proxy directives)
- apache2ctl(8) — manpages.debian.org/apache2ctl (Debian control tool)
Practice scenarios
Hands-on Apache scenarios on live Linux VMs: apache