Hosting Operations
Map Apache Virtual Hosts
You need to find Apache VirtualHost blocks and their names.
Command
grep -RInE '
What changed
Nothing changes. The command searches enabled Apache configs.
Danger
safe
When to use it
Use when a domain is served by the wrong Apache virtual host.
When not to use it
Do not assume ServerAlias coverage is complete without checking redirects and DNS too.
Undo or recovery
No undo needed because this command is read-only.
Expected output
VirtualHost, ServerName, and ServerAlias lines with file and line numbers.
demo script
Disposable terminal steps
grep -RInE 'grep -RInE '^[[:space:]]*DocumentRoot[[:space:]]' fixtures/apache/sites-enabled
simulated output
What it looks like
::fixture-ready::
$ grep -RInE '
fixtures/apache/sites-enabled/app.conf:2: ServerName app.example.com
fixtures/apache/sites-enabled/example.conf:1:
fixtures/apache/sites-enabled/example.conf:2: ServerName legacy.example.com
fixtures/apache/sites-enabled/example.conf:3: ServerAlias www.legacy.example.com
::exit-code::0
$ grep -RInE '^[[:space:]]*DocumentRoot[[:space:]]' fixtures/apache/sites-enabled
fixtures/apache/sites-enabled/app.conf:3: DocumentRoot /srv/www/app/public
fixtures/apache/sites-enabled/example.conf:4: DocumentRoot /srv/www/legacy/public
::exit-code::0
YouTube Short
Find Apache virtual hosts.
When Apache serves the wrong site, map VirtualHost, ServerName, and ServerAlias before changing redirects.
LinkedIn hook
Apache chose a virtual host. You need to know which one.
Question: When Apache serves the wrong site, what do you inspect first?
experiments
A/B tests to run
Metric: comment_rate
A: Apache chose a host.
B: Map vhosts fast.