How to Create a Meaningful Default Configuration in nginx
Introduction
The default setting of the nginx web server displays a page when no explicit configuration exists. This can be an entry point for attackers, which can be prevented by adjusting the default domain as follows.
Prerequisites
You have a hosting.fr Cloud server with a valid DNS record, for example
demo.mustermann-domain.fr.Privileged shell access on the system.
nginx is already installed on the Cloud server.
Adjusting the Default nginx Configuration
The default file (usually located under /etc/nginx/sites-enabled)
The following contents should be entered there:
server {
listen 80 default_server;
listen [::]:80 default_server;
listen 443 ssl default_server;
listen [::]:443 ssl default_server;
ssl_reject_handshake on;
server_name _;
return 444;
}
Then, check the Nginx configuration with nginx-t to ensure its validity, and restart the web server (systemctl restart nginx.service).
Note
With this configuration, no web page will be displayed when the server is directly accessed with the IP address. Appropriate vHosts for the domains should be configured beforehand! However, connections made directly via the IP will be responded to with status code 444 and terminated immediately. Thanks to the ssl_reject_handshake on; directive, it is not necessary to integrate a certificate.