A correct VirtualHost without trial and error
Hand-writing an Apache VirtualHost means remembering the right directives, a matching Directory block, the correct SSL lines, and a redirect that actually works. This builder generates the whole .conf from a short form — HTTP or HTTPS, with optional port-80 redirect, HSTS, and per-host log paths baked in.
How it works
For an HTTPS site the builder binds the main block to port 443, adds SSLEngine on with your SSLCertificateFile and SSLCertificateKeyFile, and restricts SSLProtocol to TLS 1.2 and 1.3. It pairs that with a Directory block setting sane defaults — directory listings off, symlinks followed, and Require all granted. When you enable the redirect, a second port-80 VirtualHost uses mod_rewrite to issue a permanent redirect to the https scheme. Optional HSTS adds a Strict-Transport-Security header. Error and access logs are written to per-host filenames derived from your domain so you can tail them independently.
Tips and example
- Combined PEM vs separate files: Apache uses separate certificate and key files, unlike HAProxy which wants one combined PEM — this builder keeps them separate.
- After enabling a new site, run
apachectl configtestbefore reloading to catch typos in paths. - Keep
Options -Indexesto stop Apache exposing a directory listing when an index file is missing. - If you terminate TLS at a load balancer instead, generate the HTTP variant and trust the
X-Forwarded-Protoheader in your app.