SadServers
  • Scenarios
  • Labs
    All Labs Linux & Bash Web Servers Databases Data Processing Docker Kubernetes CI/CD Infrastructure As Code Observability Tooling / Applications
  • Dashboard
  • Solutions
    For Individuals For Businesses
  • Ranking
  • Newsletter
  • FAQ
  • Documentation
    Support Pro Accounts Pro+ Accounts Business Accounts Gift API CLI/TUI Privacy Troubleshooting Interviews
  • Blog
  • Pricing
  • Gift
    Gift Purchase Gift Redeem
  • About
Log In - Sign Up
  1. Labs
  2. Apache
  3. Guide

Guide

Concepts and learning path

Troubleshooting

Failure modes and fixes

Cheatsheet

Commands to keep handy

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 files or document directories and analize logs.

How a request is handled

When a client connects, the typical workflow is:

  1. TCP accept — Apache accepts the connection on a Listen port
  2. TLS handshake — if HTTPS, mod_ssl negotiates the certificate (SNI determines which certificate to present); vhost selection happens in step 3
  3. IP/Port match — Apache selects candidate <VirtualHost> blocks that match the local IP address and port the client connected to
  4. Name based virtual host match — Apache then looks at the Host header and picks a <VirtualHost> using ServerName, ServerAlias
  5. Request processing — Apache determines the handler via DocumentRoot, Alias, ProxyPass, or rewrite rules
  6. Access check — Require directives allow or deny the request
  7. Response — static file, CGI, or proxied backend response is served; then 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 (package: `apache2`) — /etc/apache2/apache2.conf, sites in sites-available/ / sites-enabled/, modules via a2enmod / a2dismod
  • RHEL/CentOS/Rocky (packate: `httpd`) — /etc/httpd/conf/httpd.conf, vhosts in conf.d/, modules in modules/

Always run a syntax check before reload: apache2ctl configtest (Debian) or httpd -t (RHEL).

Key concepts to know

  • Virtual hosts — IP / Port first, then ServerName / ServerAlias matching against the Host header
  • Modules — LoadModule directive (or a2enmod on Debian), MPM choice (prefork/worker/event) affects performance and threading
  • Logs — ErrorLog for failures; CustomLog for access; check these first
  • Reverse proxy — ProxyPass / ProxyPassReverse to app servers (Gunicorn, Node, etc.) ProxyPreserveHost is a common pitfall
  • systemd — service unit apache2 or httpd; reload gracefully restart workers without dropping existing connections
  • .htaccess — per-directory overrides (if AllowOverride permits); slower than vhost config because Apache re-parses it per request; prefer vhost config for production

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

Troubleshooting →
SadServersSadServers

Real-world Linux and DevOps scenarios for hands-on learning and technical assessment.

Uptime Robot ratio (30 days)
Product
  • Scenarios
  • For Individuals
  • For Businesses
  • Pricing
Resources
  • FAQ
  • Blog
  • Newsletter
Company
  • About Us
  • Support
  • Privacy Policy
  • Terms of Service
  • Contact
Connect With Us
info@sadservers.com

Made in Canada 🇨🇦
Updated: 2026-07-25 13:28 UTC – d8cbd10