I have a website on a VPS.
The issue I am having is that when I enter the IP of the server, it links to the website.
Even when entering mail.domain.com, it does the
You can use redirect, nginx config:
server {
listen 80;
server_name IP_ADDRESS;
return 301 http://YOUR.DOMAIN;
}
You can just add a server directive before others.
server {
listen 80;
server_name _;
return 404;
}
Put this at top of your /etc/nginx/conf.d/SERVER_IP_ADDRESS.conf
file and comment everything what is below it.
#disabling accesing server by ip address
server {
listen SERVER_IP_ADDRESS:80 default;
server_name _;
return 404;
}
Then restart your Nginx server (on Ubuntu it is done by service nginx restart
this command)
Now when you will put your server's ip address to browser url field you will get 404 error.
You can use redirect, nginx config:
server {
listen 80;`enter code here`
server_name IP_ADDRESS;
return 301 http://YOUR.DOMAIN;
}
you can return any error you find suitable. A list of errors can be found here List_of_HTTP_status_codes
server {
listen x.x.x.x:80;
server_name x.x.x.x;
return 404;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name "";
return 444;
}
You need to specify default_server
parameter so that all non available server requests goes to this server block
which throws 444 error
.
444 : CONNECTION CLOSED WITHOUT RESPONSE
ref: https://httpstatuses.com/444