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.

Since a couple of years ago, Google Webmaster Tools site ownership verification process started to require that verification files have certain content, instead of simply being there and returning 200 OK, and making sure that other nearby files would return 404 Not Found etc.

With the new requirement, how do I serve the Google Webmaster Tools site verification file with nginx.conf alone?

share|improve this question

1 Answer 1

up vote 7 down vote accepted

If you know that the verification file should be named googled1085b59adc211cb.html (and you are told after you add a site within Webmaster Tools), then you can place the following into the appropriate server context of your nginx.conf:

    location = /googled1085b59adc211cb.html {
            rewrite ^/(.*)  $1;
            return 200 "google-site-verification: $uri";
    }

P.S. A thought experiment would reveal that it is also possible to create a location through regular expressions that would now allow anyone to verify ownership of your site at any time and without having to get in contact with you, but I will omit such configurations at this time (to prevent unintended use), since anyone genuinely interested now has a very good starting point anyways. :-)

share|improve this answer
1  
Why the rewrite as well as the return? –  Dennis Kaarsemaker Feb 9 '13 at 8:47
2  
The rewrite cleverly removes the leading / from $uri. :-) Otherwise, Webmaster Tools won't authenticate you, or you'll have to copy-paste the filename twice, making the snippet error-prone. –  cnst Feb 9 '13 at 9:38
2  
Ah, nifty, thanks! –  Dennis Kaarsemaker Feb 9 '13 at 10:17

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.