2

I have a domainname (say: example.com) for which i set the DNS records like this:

*.example.com   A   IP_ADDRESS
example.com     A   IP_ADDRESS
www.example.com CNAME example.com

This means all requests for this domain (including subdomains) will be routed to my server with address IP_ADDRESS.

On my server I have an nginx http server running, with server settings like this:

server {
    server_name demo.example.com;

    // Location blocks here
}

The behaviour I expect is that the site will only be shown when demo.example.com, while going to anything.example.com or just example.com will result in nginx giving an error.

But this is not the case, what I am actually seeing is that while i have my server_name specifically set to demo.example.com, all requests on every subdomain for this domain will route to this site. So going to anything.example.com will result in seeing the site which I only want to show when going to demo.example.com.

So, I suspect I am just being stupid here and I've misconfigured something, but could someone please tell me how to get what I expect?

jaapz
  • 989
  • 8
  • 26

2 Answers2

3

You should read how nginx process request.

You need to define catch-all server block, so that request with Host header other than demo.example.com end up in that server.

server {
    listen 80 default_server;
    return 404;
    # or return 444;
}
Alexey Ten
  • 13,794
  • 6
  • 44
  • 54
  • Yes, only minutes after posting this I actually found [this answer](http://serverfault.com/a/361420) on serverfault. Defining a server block that only returned the 404 error fixed it for me. – jaapz Jul 23 '14 at 10:58
  • Correction to my previous comment, it was this [answer](http://stackoverflow.com/a/9826635/1046386). – jaapz Jul 23 '14 at 11:12
0

you should add second default site, with servername default. There you can install any errors page.

xoid
  • 1,114
  • 1
  • 10
  • 24