How do I check which Apache virtual host serves a domain?
Apache selects a virtual host using the address, port and requested hostname. A request sent to the bare server IP can reach a default site, even when the domain’s virtual host is configured correctly. Inspect the mapping and test with the real hostname before changing document roots or DNS.
Before you start
- Access to the Apache control wrapper used by the running instance.
- The intended hostname and origin server IP.
Instructions
1. Read the virtual-host mapping
Use the appropriate wrapper for the installation. The output identifies address/port groups, default hosts and the configuration files that define them.
sudo apache2ctl -SCommon Ubuntu/Debian wrapper. On a standard RHEL-family installation use sudo apachectl -S instead.
2. Match the intended name
Locate the hostname or an intended alias in the relevant port group. Multiple matching definitions, a missing ServerAlias or a default virtual host can explain why the wrong website appears.
3. Test one origin without changing DNS
Replace the example hostname and IP with the intended values. The URL keeps the hostname for HTTP host routing and TLS verification, while --resolve selects the connection address.
curl --head --resolve app.example.com:443:203.0.113.10 --connect-timeout 5 --max-time 15 https://app.example.com/Targets one origin on TCP 443 without changing global DNS or bypassing certificate validation.
Check the result
- The mapping points to the intended site configuration and the origin test returns the expected response for that hostname.
Troubleshooting
- The certificate belongs to a different domain
- Check the HTTPS virtual-host binding and SNI configuration. Disabling certificate verification would conceal the mismatch.
- A proxy is configured for curl
- The request may follow that proxy rather than the direct-origin path; compare with the approved network path before interpreting the result.
Official references
Use the documentation for your installed version when a flag, service name or platform feature differs.
