Yandex Site Verification with Nginx on NixOS

by|inArticles||2 min read
Yandex Site Verification<br>
Yandex Site Verification<br>

Similar to Bing or Google - Yandex requires you to verify site ownership when you would like to access the statistics for your site. This can be done by meta tags, by dns entry and as well by a root level HTML file.

Many tend to use the DNS record entry or adding the meta tags in the application code (or site code). Personally I prefer to use the root level file method, here is why:

  1. The DNS record entry is not instantly. Usually DNS entries are cached and need some time to propagate.
  2. The meta tag method "pollutes" the HTML of my pages (more noise, more data transferred by each request). Furthermore I need to make changes to the application code which results in a new commit and a deployment.

So, at this point I hope that I convinced you to use the file method. And doing this on NixOS is pretty simple and fast. All we need to do is to add a new location entry for our Nginx server:

locations."/yandex_sample.html" = {
      extraConfig = '' 
        rewrite ^/(.*)  $1;
        return 200 "<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'></head><body>Verification: sample</body></html>";
      '';
    };

Save your configuration.nix file and run the rebuild command:

sudo nixos-rebuild switch

This is usually it. You can now access the file under /yandex_sample.html on your domain. (the keyword sample needs to be replaced with the code that yandex requires you to use).

Pretty simple, fast and convenient! With this method I can verify the site ownership within minutes and don't need to add any application code.

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