In some scenarios, we want visitors to only access the website through the domain name and not allow direct access via IP. This simple functionality can be achieved by configuring Nginx:

server{
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name _;
    return 403;
}

Remember to restart Nginx after making changes. Now accessing via IP will return a 403 error.