How to block access using the Server IP in NGINX?

February 28, 2019 1.8k views
Nginx Ubuntu Configuration Management

Greetings community!

I have configured a domain in my DO instance, all very well, the problem lies in being able to access the site using the IP of the Server and I really do not want that, I wish that only the site can be accessed through the domain, what type of configuration requires NGINX? or if it is not NGINX, where can I make this configuration?

Beforehand thank you very much.

1 Answer

You can add this server block to your configuration.

server {
    listen      80 default_server;
    server_name "";
    return      444;
}

You need to specify “defaultserver” parameter so that all non available server requests goes to this server block which throws 444 error. The “defaultserver” parameter cannot be present in any other server block.

444 : CONNECTION CLOSED WITHOUT RESPONSE

Have another answer? Share your knowledge.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!