Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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've got an nginx installation that serves a couple of virtual hosts; these are working fine. However, I seem to recall that this server is responsible for hosting a couple of other websites. I can't recall which ones.

I don't want these requests to resolve to the default (arbitrary) vhost.

At the moment, for example, going to (the internal address) resolves to the default vhost. This vhost is running drupal, and -- because drupal doesn't recognise the vhost -- it brings up the drupal installation instructions. I'm concerned that this is happening to other, external names that resolve to this server.

Is there a way to set up nginx so that it logs and drops requests that don't exactly match a configured vhost?

Alternatively, I guess, the question could be phrased: "How do I set up a default vhost that matches all unknown names? And how do I configure that vhost to log and drop accesses?"

share|improve this question
up vote 2 down vote accepted

Set up a default catch all server and log requests to a specific file and return some status or other. Your other known servers can be configured with known server_name values.

    log_format with_host '$remote_addr - $remote_user [$time_local] '
                        '"$request" $status $body_bytes_sent '
                        '"$http_referer" "$http_user_agent" "$host"';

    server {
            listen 80 default_server;
            location / {
                  access_log /var/log/nginx/unknown_site.log with_host;
                  return 404;       

    server {
            listen 80;
            location / {
share|improve this answer
I'd ignore the server_name, it would work with or without it, other than that the config is correct. – Mohammad AbuShady Jan 6 '14 at 9:13
Note - Roger edited this so @MohammadAbuShady comment no longer applies. – rh0dium Nov 21 '14 at 15:06

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.