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

I need not to serve robots.txt for any subdomain. For example, domain.com/robots.txt should be available, but blabla.domain.com/robots.txt should return 404.

I've tried it like so, but it didn't work:

set $subdomain FALSE;
if ($host ~* "^(([a-z0-9_\-]+)\.domain\.com)$") {
    set $subdomain TRUE;

location ~ "robots.txt$"{
    if ($subdomain = TRUE){
        return 404;
share|improve this question

1 Answer 1

up vote 1 down vote accepted
location ~ /robots.txt
       if ($host != 'domain.com') {
       return 404;
share|improve this answer
This works, but why did someone downvote this answer? –  Rakhim Davletkaliyev Jul 30 '13 at 15:25

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.