Each server{} block defines a virtual host: addresses via listen, names via server_name, and TLS settings when applicable. The default_server flag selects which block answers unmatched hosts or bare IPs. For many names, prefer explicit lists over heavy regex—ordering still matters for overlapping patterns. IPv6 listeners often pair with dual-stack [::]:443 plus IPv4 443.
| Task | Directive | Note |
|---|---|---|
| Catch-all vhost | default_server | Use for monitoring or blocking unknown Host headers |
| HTTP to HTTPS | return 301 https://$host$request_uri | Avoid redirect loops if TLS is not ready |
| Many hostnames | server_name list | Wildcards have specific rules—test SNI matches |
Related
reverse proxy, nginx SSL, nginx configuration, Apache virtual hosts (compare)