How to configure Nginx for calls to not hosted domain names

Is it possible to configure through HestiaCP (web ui or cli) the behaviour of nginx when someone call to your server IP?

Let me expose my case (i’ve read that some other people have this problem with nginx):

  • i have a server hosting a unique domain name (MYDOMAIN.com) and its own unique IP
  • but someone has set just MY IP to his domain name (OTHERDOMAIN.com)… using its DNS zones outside my server, obviously (i’ve not understood still if it has any use for the owner of that domain name)
  • so my server (nginx/hestia) is responding with a “sane” 200 if you type that domain name (OTHERDOMAIN.com) in browser or call it with a terminal PING, curiously just as it was an “alias” of MYDOMAIN.com
  • i would like to be able to configure nginx to return a 404 code for any other domain name not configured by me through Hestia
  • i’ve searched on internet and discovered that i can manually configure nginx files for domains, but i unknow if this settings will remain after the next Hestia update… i suppose it don’t.

So, any clue or suggestion?

If the domain has not been configured with in Hestia is should show by default:

Just add return 404 to /etc/nginx/conf.d/ip.conf

1 Like

Many thanks!! After search by some minutes on internet and some attempts i got it run with a simple configuration. I want to share it here for others.

You must edit the nginx config file for your IP:

nano /etc/nginx/conf.d/123.123.123.123.conf

And then set this content (replace 123.123.123.123 by your server IP):

server {
    listen       123.123.123.123:80 default;
    server_name  _;
    return 404;
}

server {
    listen      123.123.123.123:443 ssl http2;
    server_name _;
    ssl_certificate      /usr/local/hestia/ssl/certificate.crt;
    ssl_certificate_key  /usr/local/hestia/ssl/certificate.key;
    return 404;
}

Indeed, to activate this new settings, restart Nginx service:

sudo service nginx restart

And voilà!! :slight_smile:

2 Likes

Isn’t that file going to be re-written after an hestia update?

No, that file will not be touched.

Hello there,

I have a question about Hestia’s default configuration. Can you explain to me why Hestia is set up to respond to domains that are not present on the server?

I currently use Cloudflare for DNS, and I’ve noticed that Hestia responds to requests for all domains pointed from Cloudflare, even if those domains are not yet configured on Hestia. This seems a bit odd to me. Can you help me understand what I might be missing here?
Thanks.

It loads then default page in /var/www/html as any server does if you access over ip

1 Like