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?


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. :-)

  • 2
    Why the rewrite as well as the return? – Dennis Kaarsemaker Feb 9 '13 at 8:47
  • 4
    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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.