Block Requests with No Host Header

Just wondering—if I add this to the NGINX file, would it solve the problem? Maybe something to include in the config file by default?

http block in NGINX config:

map $http_host $bad_host {
    "" 1;
    default 0;
}

In the server block:

server {
    listen 80;
    server_name example.com;

    if ($bad_host) {
        return 400 "Missing Host header";
    }

    location / {
        proxy_pass http://localhost:3000;
    }
}

Would this work, or would I need to change anything? Any tips would be a great help.

If you need to specify a single domain, that is, a specific domain to take effect, please modify the relevant domain configuration in the/home/user/conf/web/myweb/directory.
Remember to restart the relevant applications after editing! In order to make it effective!