Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

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.

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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