From d4b71942d7f1840ad4c1a0500f59df029b92cc04 Mon Sep 17 00:00:00 2001 From: Konstantin Nazarov Date: Tue, 15 Aug 2023 17:07:16 +0100 Subject: [PATCH] Block some of the bots on my website --- nodes/knazarovcom/configuration.nix | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/nodes/knazarovcom/configuration.nix b/nodes/knazarovcom/configuration.nix index 41885ea..e042e7b 100644 --- a/nodes/knazarovcom/configuration.nix +++ b/nodes/knazarovcom/configuration.nix @@ -37,6 +37,13 @@ services.nginx = { enable = true; + commonHttpConfig = '' + map $http_user_agent $limit_bots { + default 0; + ~*(AhrefsBot|PetalBot|bingbot|gptbot|ZoominfoBot|BLEXBot|Bytespider) 1; + ~*(DecompilationBot|Amazonbot|Barkrowler|SeznamBot) 1; + } + ''; virtualHosts = { "knazarov.com" = { enableACME = true; @@ -56,11 +63,25 @@ add_header "Access-Control-Allow-Origin" *; ''; }; + locations."/" = { + extraConfig = '' + if ($limit_bots = 1) { + return 403; + } + ''; + }; }; "vmatveeva.com" = { enableACME = true; forceSSL = true; root = "${pkgs.vmatveevacom}/srv/vmatveeva.com"; + locations."/" = { + extraConfig = '' + if ($limit_bots = 1) { + return 403; + } + ''; + }; }; "matrix.knazarov.com" = { enableACME = true;