Linux Advanced 08 — Apache Virtual Hosts and HTTPS

Linux course index · Linux Advanced category · Lesson 8 of 9

AI disclosure — AI-generated content, posted as is. AI can make mistakes. This lesson draws on the linked Open Education posts and adds original explanations or lab examples where useful. The newly written explanations and examples may be freely reused. Linked source material retains its own terms.

Learning goal

Test Apache name-based routing locally and verify HTTPS with certificate and renewal checks.

Concepts and setup

A virtual host maps the requested host and port to settings and a DocumentRoot. A client sends an HTTP Host header. For HTTPS, TLS starts before HTTP and SNI usually helps the server choose a certificate. The site’s Certbot procedure assumes an authorized public domain. You cannot get a public certificate for a private .test hostname. Use a disposable Ubuntu or Debian VM with Apache installed for the first lab.

Create one name-based vhost and test it from the same VM

sudo install -d -m 0755 /var/www/oe-linux-test
printf 'Open Education Apache lab\n' | sudo tee /var/www/oe-linux-test/index.html
sudo tee /etc/apache2/sites-available/oe-linux-test.conf >/dev/null <<'EOF'
<VirtualHost *:80>
    ServerName web.example.test
    DocumentRoot /var/www/oe-linux-test
</VirtualHost>
EOF
sudo a2ensite oe-linux-test
sudo apachectl configtest && sudo systemctl reload apache2
curl -fsS --resolve web.example.test:80:127.0.0.1 http://web.example.test/

Possible output

Open Education Apache lab
Enabling site oe-linux-test.
Syntax OK
Open Education Apache lab

Use unused file names. –resolve targets loopback while keeping the requested hostname. After testing, run a2dissite oe-linux-test, test and reload the config, and remove only these fixture files.

On a separate domain you manage, verify trust and renewal

# Replace www.example.com with your authorized domain.
curl -IsS https://www.example.com/
# On that server, after legitimate Certbot setup:
sudo certbot certificates
sudo certbot renew --dry-run

Possible output

HTTP/2 200
...
Certificate Name: www.example.com
...
Congratulations, all simulated renewals succeeded: ...

These commands verify an existing deployment. To obtain a certificate, use the CA’s supported validation procedure. HTTP-01 uses incoming port 80. DNS-01 uses a DNS TXT challenge and can suit a service that is not public over HTTP. Do not use curl -k as evidence of trust.

Questions only

Quick-check questions

  1. Why can a browser reject a certificate from a known CA?
  2. Does apachectl configtest prove that the client sees the right website?

Assessment questions

  1. The default vhost answers instead of the new site. What do you verify?
  2. What evidence should a certificate-renewal checklist include?
  3. When would you consider DNS-01 instead of HTTP-01?

Questions and answers

Quick-check answers

  1. Why can a browser reject a certificate from a known CA?
    Answer — The requested name may not match, the certificate may be expired, or the chain may be unsuitable.
  2. Does apachectl configtest prove that the client sees the right website?
    Answer — No. It validates configuration syntax, not application routing.

Assessment answer key

  1. The default vhost answers instead of the new site. What do you verify?
    Answer — Inspect apachectl -S, the enabled vhost, listener port, ServerName, and the name the client actually sends.
  2. What evidence should a certificate-renewal checklist include?
    Answer — Verify hostname and chain from a client, check expiry, perform an authorized renewal dry run, and confirm automatic scheduling.
  3. When would you consider DNS-01 instead of HTTP-01?
    Answer — When you control DNS validation and do not want to make the web server publicly reachable on port 80, or need a wildcard certificate.

Source articles on this site

Technical references

Continue the course

Previous lesson 07 — Time Synchronization with chrony. Next lesson 09 — MariaDB Service Accounts and Restore Verification.

Linux course index · Linux Advanced category · Lesson 8 of 9

Leave a Reply