The following is the official configuration of nginx:
server {
listen 80;
server_name "";
return 444;
}
https://nginx.org/en/docs/htt...
But it seems that it only supports http. If https is used, the domain name will be used regardless of where it is configured and whether it is configured default_server
Access and IP direct access 444.
server {
listen 80;
listen [::]:80;
server_name example.com;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name example.com;
if ( $host = $server_addr ) {
return 444;
}
# ...
}
https://paste.ubuntu.com/2340...
This is how I configure it now. http request 301 jumps to https, and then use if to detect if the request is made using the server IP address, it will be 444. But this is not a good configuration (https://www.nginx.com/resourc..., is there a better configuration practice?
server {
}