How to use it
- Enter the domain without
http://and decide whetherwww.should work too. - Enter the document root, for example
/var/www/example.com/public. - For HTTPS, keep the certificate fields empty if you use certbot, or enter your own paths.
- Choose the extras, copy the config and follow the note under it to enable the site.
How it works
ServerNameandServerAliasdecide which requests the block answers.<Directory>grants access with the Apache 2.4 syntaxRequire all granted, setsOptions -Indexes +FollowSymLinks(or+Indexesfor listings) andAllowOverride AllorNone.- With HTTPS, the 443 block adds
SSLEngine onand the certificate files; the 80 block either redirects withRedirect permanent / https://domain/or serves the same site. - HTTP/2 adds
Protocols h2 http/1.1(module http2), HSTS addsHeader always set Strict-Transport-Security "max-age=31536000"(module headers). - Logs go to
<folder>/<domain>-error.logand<domain>-access.login the combined format.
Example
For example.com with www, HTTPS, redirect, HTTP/2 and logs, the port 80 block is:
<VirtualHost *:80>
ServerName example.com
ServerAlias www.example.com
Redirect permanent / https://example.com/
</VirtualHost>
The port 443 block has the same names, DocumentRoot /var/www/example.com/public, the <Directory> section, the two log lines and:
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
Protocols h2 http/1.1
Tips
- Run
apachectl configtestbefore every reload: a typo stops Apache from starting. - Get the certificate first (
certbot certonly --webrootor with the HTTP-only config), then switch on HTTPS; Apache will not start if a certificate file is missing. - Make the files in the document root readable by the Apache user (www-data or apache) and keep secrets outside it.