I have two server {} blocks with the domains I need to use.

But I have found a problem..... if I configure the DNS of another domain that point to my server, nginx response correctly! Why?

Nginx should response with a http Error! but it returns the website that have the same IP address, why? I don't have a server name with that domain!

Thank you!


It responds because you don't have a separate 'default' vhost configured. There is always a default, or fallback, vhost configured, so that nginx knows what to do in the event it gets a request of the type you've sent.

The nginx documentation provides a good description of how the server-name-to-vhost-matching is performed, but in short I'd recommend configuring a new vhost like this:

server {
  listen 80 default_server;
  root /usr/share/empty;

(You may have to create /usr/share/empty if it doesn't already exist)

This will simply serve an empty directory to anyone who hits your server with an unrecognized vhost name. You can get fancier with various sorts of error pages and whatnot if you like.

  • 2
    root /usr/share/empty; can be replaced with return 404; – hlcs Jul 13 '14 at 16:19
  • That you can. Good tip! – womble Jul 14 '14 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.