Blog · Articles tagged with "nginx" · show all articles »

How to configure Nginx to return an error for requests without a matching host

When you host multiple apps on the same server using Nginx, you probably define multiple virtual servers like this:

server {
  server_name my-awesome-app.com;
  ...
}

server {
  server_name another-brilliant-app.com;
  ...
}

server {
  server_name such-a-fantastic-app.com;
  ...
}

Then you set up a monitoring servive like Pingdom for each app to make sure you are notified if anything bad should happen and one of the apps would go down. The next day a coworker decides such-a-fantastic-app.com is no longer needed and removes that server blog from the Nginx config. But hey, since you set up monitoring, you will get a notification immediately, right?

Well, you guessed it, WRONG!

Read on