Directives and Containers

Directives, Sections and Containers

A directive is one line: a case-insensitive name and its arguments. Quote arguments containing spaces, continue a line with a trailing \, and put # comments on lines of their own. A section wraps directives in tags. Conditional sections (<IfModule>, <IfDefine>, <IfFile>) are decided once at startup; containers (<VirtualHost>, <Directory>, <Files>, <Location>, their Match forms and <If>) apply per request to part of the URL space or filesystem.

Apache 129 enforces the contexts each directive's manual page allows, and apache2ctl configtest (or -t) parses everything without touching the running server:

A configuration snippet with a misspelled directiveXML
<Directory "/var/www/site-a">
  DirectoryIndx index.html
</Directory>
Output
AH00526: Syntax error on line 2 of /etc/apache2/conf-enabled/typo.conf:
Invalid command 'DirectoryIndx', perhaps misspelled or defined by a module not included in the
server configuration

It exits with status 1. Header fails the same way until mod_headers is loaded, which is what <IfModule headers_module> guards, and a <Directory> nested in a <Location> fails with <Directory not allowed in <Location> context. Chain the check to every reload, sudo apache2ctl configtest && sudo systemctl reload apache2; the reload is a graceful restart that lets requests in flight finish.