12

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?

1 Answer 1

20

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
  • 2
    Why the rewrite as well as the return? Feb 9, 2013 at 8:47
  • 5
    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, 2013 at 9:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .