NCAE Mapping Hub
Overview Scoreboard Data Roles Exercised Checklists Lessons Skill Drills Practice Terminal Progress
published priority 15 35 min. 55 XP.

Apache VirtualHosts + SSL. Serving WWW Content and WWW SSL

Three NCAE services score against your web server: WWW Port 80 (is HTTP alive), WWW Content (does the admin login work), WWW SSL (is HTTPS + valid cert up). This lesson covers Apache2's module + sites-enabled model, how VirtualHosts route requests, and how to regenerate a self-signed cert fast.

Objectives

Quick reference

CommandPurpose
apachectl -V Show Apache build info and compiled modules
apachectl -S Dump VirtualHost routing table (settles most 'which vhost wins' arguments)
apachectl configtest Syntax check (or apache2ctl -t)
systemctl reload apache2 Pick up config changes without dropping connections
systemctl restart apache2 Hard restart (drops all connections)
a2enmod ssl Enable a module
a2ensite default-ssl Enable a site
tail -f /var/log/apache2/error.log Real-time error log
tail -f /var/log/apache2/access.log Real-time access log
openssl x509 -in /etc/ssl/certs/server.crt -noout -dates -subject Inspect cert
curl -vk https://localhost/ 2>&1 | grep 'subject\|issuer' What cert is Apache serving right now

Common pitfalls

How it works (walkthrough)

# A minimal SSL VirtualHost
# /etc/apache2/sites-available/default-ssl.conf
<IfModule mod_ssl.c>
  <VirtualHost *:443>
    ServerName team10.ncaecybergames.org
    DocumentRoot /var/www/html
    SSLEngine on
    SSLCertificateFile      /etc/ssl/certs/server.crt
    SSLCertificateKeyFile   /etc/ssl/private/server.key
    ErrorLog  ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
  </VirtualHost>
</IfModule>

# Regenerate a self-signed cert with correct CN + SAN (60-second fix):
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
  -keyout /etc/ssl/private/server.key \
  -out /etc/ssl/certs/server.crt \
  -subj "/CN=team10.ncaecybergames.org" \
  -addext "subjectAltName=DNS:team10.ncaecybergames.org"
chmod 600 /etc/ssl/private/server.key
chmod 644 /etc/ssl/certs/server.crt
systemctl restart apache2

Skill drills

  1. 1. Debian command to enable an Apache site?
    a2ensite <site>
  2. 2. Apache command to dump its routing table?
    apachectl -S
  3. 3. What's the permission mode for an SSL private key file?
    600 (owner read/write only)
  4. 4. What Apache directive sets the CN-matching name for a vhost?
    ServerName
  5. 5. OpenSSL command to generate a self-signed cert with a specific CN?
    openssl req -x509 -subj '/CN=<name>' .
  6. 6. What module handles HTTPS in Apache?
    mod_ssl

NCAE scoreboard patterns this lesson prevents