Google Site Verification with Nginx on NixOS

by|inArticles||1 min read
NixOS Logo
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!

Hey, quick note, are you running a NixOS server? Netcup may be a good replacement, cheaper and faster servers. Ersocon is running on exactly those servers. Check out as well How to run a NixOS Server on Netcup.

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

Related Articles

© Copyright 2024 - ersocon.net - All rights reservedVer. 415