Nginx Server Block Selection Checklist

halfbrain_logo512adminJune 19, 2026
2 lượt xem

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

  1. List all enabled Nginx server blocks.
  2. Check all listen directives.
  3. Check duplicate server_name values.
  4. Check default_server declarations.
  5. Check HTTP and HTTPS blocks separately.
  6. Check www and non-www behavior.
  7. Check wildcard or catch-all blocks.
  8. Use curl with host header if needed.
  9. Check access log to confirm selected block.
  10. 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.

Checklist Type Troubleshooting
Level Intermediate
Risk Level Medium Risk
Estimated Time 30–75 minutes

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

  1. List enabled blocks.
  2. Check listen directives.
  3. Check duplicate names.
  4. Check default_server.
  5. Check HTTP block.
  6. Check HTTPS block.
  7. Check www handling.
  8. Test host header.
  9. Confirm with logs.
  10. Fix conflicts.

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

Share:

Disclaimer: The guides, checklists, commands, and examples on HalfBrain.net are provided for educational and operational reference only. Server environments, hosting providers, software versions, security settings, and WordPress configurations can vary, so you should always review commands before running them on your own system. We do our best to keep the content accurate and useful, but we cannot guarantee that every command, configuration, or recommendation will fit every environment. Always back up your website, database, and server configuration before making changes. HalfBrain.net is not responsible for data loss, downtime, security incidents, misconfiguration, or other issues that may result from applying the information on this website. Use the material at your own discretion.

Leave a Reply

Your email address will not be published. Required fields are marked *