How do I verify site ownership on Google Webmaster Tools through nginx.conf?

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?


Solution 1:

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