0

Nginx responds to

subdomain.example.com

as it would to

example.com

when I specified only to listen to example.com and www.example.com

Here is my config:

server {
   listen 443 ssl;
   server_name example.com;
   server_name www.example.com;
   ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
   ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
   ssl_prefer_server_ciphers on;

   location / {
        proxy_pass http://internal_server:3000;

        proxy_set_header        Host $host;
        proxy_set_header        X-Real-IP $remote_addr;
        proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header        X-Forwarded-Proto $scheme;
   }
}

where example.com is replaced with the actual domain and internal_server is replaced with the internal server

MrShoe
  • 31
  • 6
  • 1
    That's because your server block being the only one listening 443 port acts as a default server. Read the [documentation](http://nginx.org/en/docs/http/request_processing.html). – Ivan Shatsky May 15 '22 at 08:10
  • If you want to block the requests containing wrong `Host` HTTP header, check [this](https://stackoverflow.com/a/69825652/7121513) answer. – Ivan Shatsky May 15 '22 at 18:07

0 Answers0