Apache virtual host generator

Enter the domain and the folder with the site files, choose HTTPS and the extras, and copy a complete Apache 2.4 configuration: the port 80 block with a redirect and the port 443 block with certificates, directory permissions and logs.

The folder with the site files, an absolute path.
Leave empty for the Let's Encrypt paths in /etc/letsencrypt/live/<domain>/.

Debian/Ubuntu: save as /etc/apache2/sites-available/<domain>.conf, then a2ensite <domain>, a2enmod ssl headers http2 as needed, apachectl configtest and systemctl reload apache2.

Runs in your browser: nothing you enter is sent anywhere.

How to use it

  1. Enter the domain without http:// and decide whether www. should work too.
  2. Enter the document root, for example /var/www/example.com/public.
  3. For HTTPS, keep the certificate fields empty if you use certbot, or enter your own paths.
  4. Choose the extras, copy the config and follow the note under it to enable the site.

How it works

  • ServerName and ServerAlias decide which requests the block answers.
  • <Directory> grants access with the Apache 2.4 syntax Require all granted, sets Options -Indexes +FollowSymLinks (or +Indexes for listings) and AllowOverride All or None.
  • With HTTPS, the 443 block adds SSLEngine on and the certificate files; the 80 block either redirects with Redirect permanent / https://domain/ or serves the same site.
  • HTTP/2 adds Protocols h2 http/1.1 (module http2), HSTS adds Header always set Strict-Transport-Security "max-age=31536000" (module headers).
  • Logs go to <folder>/<domain>-error.log and <domain>-access.log in 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 configtest before every reload: a typo stops Apache from starting.
  • Get the certificate first (certbot certonly --webroot or 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.

Frequently asked questions

Where does the file go?

On Debian and Ubuntu, in /etc/apache2/sites-available/ as example.com.conf, enabled with a2ensite example.com. On RHEL, Fedora and similar systems, in /etc/httpd/conf.d/ as example.com.conf, which is read automatically. Reload Apache afterwards.

Why are there two VirtualHost blocks?

One listens on port 80 for plain HTTP, the other on 443 for HTTPS. With the redirect on, the port 80 block only sends visitors to the HTTPS address with a 301, keeping the name and alias so both example.com and www.example.com are redirected.

Which certificate files do I use with Let's Encrypt?

certbot stores them in /etc/letsencrypt/live/<domain>/: fullchain.pem for SSLCertificateFile and privkey.pem for SSLCertificateKeyFile. Since Apache 2.4.8 the certificate file may contain the whole chain, so SSLCertificateChainFile is not needed.

What does AllowOverride All change?

It lets .htaccess files in the document root change the configuration, which many PHP applications rely on for clean URLs. With None Apache does not read .htaccess at all, which is slightly faster; put the rules into the virtual host instead.

Should I turn on HSTS?

Only when the site and every subdomain you use work over HTTPS. Browsers that saw the header refuse plain HTTP for the domain for the whole max-age, one year here, even if you later remove HTTPS.

What is ${APACHE_LOG_DIR}?

A variable defined in Debian and Ubuntu's envvars file, normally /var/log/apache2. On other systems enter a real folder such as /var/log/httpd.

More in Developer

All tools in this category: Developer ·Updated November 4, 2026

Privacy choices

Google Analytics shows us which tools are used and whether they work. It may set cookies. Your choice is kept in this browser.