Handle the default request


#1

Hi there,

I’m sure there’s a lot of people hosting their customers on EE here and the most frustrating thing is when they point their entire domain to the server or their domain alternative.
So if someone has website.com domain and point thewebsite.com domain to our server, by default nginx redirects you to alphabetically first config available.
So for V4 I got this extra file called everythingelse.conf in nginx-proxy configuration with this setup:

server {
  listen       80 default_server;
  server_name  everythingelse;

  error_page 404 /404.html;

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

This seems to be doing the job, hower, I cannot figure out how to do this for 443 port (https).
Any clues? Also, it would be great if that was built in EE feature (404 for not found hosts rather than default nginx redirect)


#2

you can add 443 in listen as well.
If you want to do a redirect on every http request you can use this :

server {
    listen 80;

    server_name foo.com;
    return 301 https://foo.com$request_uri;
}
server {
    listen 443 ssl default_server;
    server_name foo.com;
}

more info : https://serversforhackers.com/c/redirect-http-to-https-nginx


#3

Could you please not post unrelated responses. This has nothing to do with the subject.