Hi,

You might be aware that if a DNS request point your nginx server.

and this later do not have a server rule for it , nginx will server anyway the first server found in your config file, WTF !

So I’ve found https://stackoverflow.com/a/23281442

server {
  listen       80 default_server;
  server_name  everythingelse;

  error_page 404 /404.html;

  # Everything is a 404
  location / {
    return 404; #return the code 404
  }

  # link the code to the file
  location = /404.html {
    #EDIT this line to make it match the folder where there is your errors page
    #Dont forget to create 404.html in this folder
    root  /var/www/nginx/errors/;
  }
}

But this is not working !

I made one of my domain pointing to this nginx server, and he still server another site aka server For httpS for http nothing appear…

Thanks.

    • Rick_C137@programming.devOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      edit-2
      5 months ago

      I wanted to have a default server that catch ~wrong DNS query to the server

      Solution

      I don’t know how to link to my previous lemmy post, so here it is again

      server {
          listen 443 ssl;
          server_name _;
          ssl_certificate /etc/nginx/ssl/catchall.crt;
          ssl_certificate_key /etc/nginx/ssl/catchall.key;
      
          error_page 404 /404_CatchAll.html;
      
          # Everything is a 404
          location / {
              return 404;
          }
      
          location /404_CatchAll.html {root /var/www/html/;}
      }