Skip to content

Configuring a Subdomain with Apache

This guide shows you how to set up a subdomain (e.g., wiki.mus.is) to serve your documentation.

1. DNS Configuration

Ensure you have created a DNS A record for your subdomain (e.g., wiki.mus.is) pointing to your server’s IP address.

2. Create an Apache Virtual Host File

Create a file named wiki.mus.is.conf in /etc/apache2/sites-available/ with the following content:

<VirtualHost *:80>
    ServerName wiki.mus.is
    DocumentRoot /var/www/wiki/site

    ErrorLog ${APACHE_LOG_DIR}/wiki.mus.is_error.log
    CustomLog ${APACHE_LOG_DIR}/wiki.mus.is_access.log combined

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =wiki.mus.is
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName wiki.mus.is
    DocumentRoot /var/www/wiki/site

    ErrorLog ${APACHE_LOG_DIR}/wiki.mus.is_error.log
    CustomLog ${APACHE_LOG_DIR}/wiki.mus.is_access.log combined

    Include /etc/letsencrypt/options-ssl-apache.conf

    <Directory /var/www/wiki/site>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    SSLCertificateFile /etc/letsencrypt/live/wiki.mus.is/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/wiki.mus.is/privkey.pem
</VirtualHost>
</IfModule>

3. Enable the Virtual Host and Reload Apache

sudo a2ensite wiki.mus.is.conf
sudo systemctl reload apache2

4. Secure the Subdomain with Certbot (Optional)

To obtain and deploy an SSL certificate:

sudo certbot --apache -d wiki.mus.is

Follow the interactive prompts to complete the setup.