Setting Up an Apache VirtualHost
August 10, 2026 · DevTools
An Apache VirtualHost block tells the server how to handle a specific site. It opens with <VirtualHost *:80> (or *:443 for SSL), sets a ServerName that matches the domain, an optional ServerAlias, and a DocumentRoot pointing at the files to serve. A nested <Directory> block controls access and options — under Apache 2.4 that means Require all granted, and AllowOverride All lets a .htaccess file in that directory take effect.
For HTTPS, the vhost moves to port 443 and adds SSLEngine on plus the certificate and key file paths. Once the file is written under sites-available, you enable it with a2ensite and reload Apache. Run one HTTP vhost that redirects to HTTPS and one SSL vhost that serves the site, and you have a clean, secure setup.