Nginx Server Block Selection Checklist
When multiple websites run on one VPS, Nginx chooses a server block based on listen address, port and server_name. If selection is wrong, a domain may show the wrong website, default page, SSL error or unexpected redirect.
Core principle
Nginx server block selection is deterministic. A request matches by address, port and hostname. If no exact hostname matches, the default server may handle it.
Checklist
- List all enabled Nginx server blocks.
- Check all listen directives.
- Check duplicate server_name values.
- Check default_server declarations.
- Check HTTP and HTTPS blocks separately.
- Check www and non-www behavior.
- Check wildcard or catch-all blocks.
- Use curl with host header if needed.
- Check access log to confirm selected block.
- Remove or fix conflicting blocks.
Reusable lesson
This applies to multi-site VPS hosting, staging domains, domain migrations, SSL setup, Cloudflare origin routing and parked domains.
When to Use This Checklist
Use this checklist when a domain loads the wrong website, default Nginx page, unexpected SSL certificate or wrong redirect.
Required Tools
SSH access, Nginx enabled sites, nginx -T, curl, domain list, DNS records
Before You Start
Do not assume the visible domain proves the correct server block is being used. Confirm selection from config and logs.
Structured Checklist Steps
- List enabled blocks.
- Check listen directives.
- Check duplicate names.
- Check default_server.
- Check HTTP block.
- Check HTTPS block.
- Check www handling.
- Test host header.
- Confirm with logs.
- Fix conflicts.
Verification Steps
- No duplicate server_name conflict remains.
- Default server is intentional.
- HTTP and HTTPS route correctly.
- www and non-www behavior is clear.
- Wrong-site loading is resolved.
Rollback Plan
If fixing a conflict breaks another domain, restore the previous config and separate domains into clear server blocks before reloading again.
Common Mistakes
- Duplicate server_name across files.
- Forgetting HTTPS block.
- Unexpected default_server.
- Not testing www version.
- Leaving old migration blocks enabled.
Related Commands
ls -la /etc/nginx/sites-enabled/
sudo nginx -T | grep -n "server_name"
sudo nginx -T | grep -n "default_server"
curl -I http://example.com
curl -I https://example.com
curl -H "Host: example.com" -I http://127.0.0.1