basforge

Search titles, text and the “If it doesn’t work” cases.

    RU

    default_server catch-all — without it, hitting the IP serves another site and its certificate

    When the Host header matches no server_name, nginx routes the request to the first server block on that port — and on port 443 exposes its TLS certificate. A dedicated catch-all block with return 444 and ssl_reject_handshake on closes this leak.

    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_server block with ssl_reject_handshake on;, so nginx returned the first SSL server block it found.
    Fix
    Add /etc/nginx/conf.d/00-default.conf with listen 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.conf is still in /etc/nginx/conf.d/ and claims port 80.
    Fix
    Delete default.conf, keep 00-default.conf, and run sudo nginx -t && sudo systemctl reload nginx.