Nginx

How to verify Google Webmaster with Nginx

Posted on by

In previous blog posts we already have seen how to verify a property for Google Webmaster Tools at application level (Scala, Haskell). In this very short tutorial we will see how to achieve this with Nginx with only a couple of lines of code.

To verify a site in Nginx it is enough to add an additional location entry to your server configuration:

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

location / {
    // the default configuration goes here   
}

As you can see, we "intercept" the request for the HTML resource and immediately return a simpe 200 response with the requested URI as the content (which Google Site verification requires). After adding this part to your Server configuration we just need to restart our Nginx server:

sudo systemctl restart nginx

From now on your site verification process should pass. If you have any questions or comments, let us know in the section below.