Skip to content

Instantly share code, notes, and snippets.

@drewgates
Last active June 17, 2017 17:22
Show Gist options
  • Save drewgates/06f05ff0e8808beb04861cdcc795cd2d to your computer and use it in GitHub Desktop.
Save drewgates/06f05ff0e8808beb04861cdcc795cd2d to your computer and use it in GitHub Desktop.

Apache Config Files, by default, are stored in /etc/apache2/sites-available, and the naming convention for the vhost configuration files is 'example.com.conf'

Before creating a vhost, add a webroot directory for that host (mkdir /var/www/example.com/)

Create a config file for the vhost, and paste in the config below. If you are not using SSL, use the top section only.

edit as necessary to use your domain name/folder name.

<VirtualHost *:80> ServerName drew.ga ServerAlias www.drew.ga

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/drew.ga

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

<VirtualHost *:443> ServerName drew.ga ServerAlias www.drew.ga SSLEngine on SSLCertificateFile /etc/letsencrypt/live/drew.ga/cert.pem SSLCertificateKeyFile /etc/letsencrypt/live/drew.ga/privkey.pem SSLCertificateChainFile /etc/letsencrypt/live/drew.ga/chain.pem ServerAdmin webmaster@localhost DocumentRoot /var/www/drew.ga

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
    <Directory /var/www/drew.ga>
       AllowOverride All
    </Directory>

Once the vhost config is saved, use 'sudo a2ensite example.com.conf' to enable the vhost and 'sudo service apache2 reload' to reload the apache config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment