11

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?

cnst
  • 12,948
  • 7
  • 51
  • 75

1 Answers1

19

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

cnst
  • 12,948
  • 7
  • 51
  • 75
  • 2
    Why the rewrite as well as the return? – Dennis Kaarsemaker Feb 09 '13 at 08: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 09 '13 at 09:38