Ready catch-all block
# /etc/nginx/conf.d/00-default.conf — one for the whole server
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
return 444;
}
server {
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
server_name _;
ssl_reject_handshake on;
}
On port 80, status 444 drops the connection with no response. On port 443, ssl_reject_handshake on (nginx 1.19.4+) aborts the TLS handshake with unrecognized name before sending any certificate (Hardening, HTTPS & HTTP/3).
If it doesn’t work
Opening https://203.0.113.10 triggers a browser certificate warning showing a domain hosted on the server
- Cause
- Port 443 has no
default_serverblock withssl_reject_handshake on;, so nginx returned the first SSL server block it found. - Fix
- Add
/etc/nginx/conf.d/00-default.confwithlisten 443 ssl default_server; ssl_reject_handshake on;.
The port 80 catch-all doesn’t trigger; nginx serves the stock Welcome to nginx! page instead
- Cause
- The package’s stock
default.confis still in/etc/nginx/conf.d/and claims port 80. - Fix
- Delete
default.conf, keep00-default.conf, and runsudo nginx -t && sudo systemctl reload nginx.