How to edit nginx default.conf to solve bad redirects?

I’ll try to explain the best I can with a couple scenarios…
The file in question is /opt/easyengine/services/nginx-proxy/conf.d/default.conf

I have a couple of sites with https enabled through letsencrypt and if one of the sites certificate expire and isnt renewed on time, then you will get redirected to the first domain in default.conf which isnt always desirable. Another scenario is if you setup a subdomain at your dns provider which points to your server but you havent created the site yet (ee site create then you also get redirected.

I’m well aware that both of above situations should never happen and can easily be avoided but its just an extra precaution which is good to have if stuff breaks unknowingly for some reason. However the main issue is if you enter the IP of the server, then you also get the first domain in default.conf.

My preferred action would instead be to redirect a’la 444 whenever you try to access the server directly by its IP adress.

A solution to this would be to edit the current default.conf server section from

server_name _;
listen 80;
return 503;


    listen 80 default_server;
    listen 443 ssl default_server;
    server_name _;
    ssl_certificate /etc/nginx/certs/;
    ssl_certificate_key /etc/nginx/certs/;
    return 444;

More information on where I found the solution is on

Issue is that you can’t directly edit default.conf since it just gets replaced as soon as you reload nginx due to the docker setup I guess.

Anyone know a possible solution?