Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If my configuration looks something like

server {
  listen 80;
  server_name example.com;
}

how do I refuse requests to subdomain.example.com?

share|improve this question
add comment

3 Answers

up vote 3 down vote accepted
server {
    listen 80;
    server_name subdomain.example.com;
    deny all;
}

Or, if you wanted to drop all traffic that wasn't to a domain explicitly defined in another server block in your config:

server {
    listen 80 default_server;
    server_name _;
    deny all;
}
share|improve this answer
add comment

Shane Madden's answer will work, or you may also use the non-standard response code 444, which will kill the connection without sending any headers (source: http://wiki.nginx.org/HttpRewriteModule)

To block specific subdomains:

server {
    server_name subdomain.example.com;
        return 444;
}

Or to block all subdomains or domains that are not handled elsewhere:

server {
    server_name _;
    return 444;
}

The latter option is useful when blocking domains that are duplicating your content and thus may hurt your search engine rankings. (This comes from personal experience.)

share|improve this answer
add comment

If your subdomain have trafic, better redirect all request from subdomain to domain like this

        if ($http_host != "example.com") {
            rewrite ^ http://example.com$request_uri permanent;
    }

in server section

It's SEO friendly.

share|improve this answer
    
In this case that's explicitly what I don't want to do though. Thanks. –  Tom Jan 7 '12 at 19:52
add comment

Your Answer

 
discard

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.