Google Site Verification with Nginx on NixOS

byAlexej Bondarenko|20.05.2022
NixOS Logo

To get access to your site on Google Webmaster Tools, you need to verify the ownership of your site. In many cases developers tend to implement this kind of verification in application code.

As I already showed in another post this is not really necessary and can be easily done by configuring your proxy server, for instance Nginx.

When I switched my project from Ubuntu to NixOS based servers, I had to port as well my nginx configuration. The code below should give you an idea how your configuration.nix file should look like if you are planning to do the same. 

  virtualHosts."mydomain.com" = {
      enableACME = true;
      forceSSL = true;

      locations."/googleCODE.html" = {
        extraConfig = ''
          rewrite ^/(.*)  $1;
          return 200 "google-site-verification: googleCODE.html";
        '';
      };

      locations."/" = {
        proxyPass = "http://localhost:8000";
      };
    };
  };

As you can see, the configuration is pretty simple. The trick is the extraConfig property for the google verification location. You just need to replace "CODE" with your real google verification code. That's it!

Thank you for reading this far! Let’s connect. You can @ me on Twitter (@debilofant) with comments, or feel free to follow. Please like/share this article so that it reaches others as well.

© Copyright 2022 - Ersocon - All rights reservedVer. 2.3.2.12