Skip to content

Instantly share code, notes, and snippets.

@ryancdotorg
Created March 2, 2022 15:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryancdotorg/1b41af4b19ff18d91d717be575ec295d to your computer and use it in GitHub Desktop.
Save ryancdotorg/1b41af4b19ff18d91d717be575ec295d to your computer and use it in GitHub Desktop.
anti-bot nginx snippet
location ~ ^/private/.*[.]html$ {
try_files /$d_pelican$uri /$d_pelican$uri/index.html /_web$uri @tryredir;
# can check $request_filename
set $h_robots "noindex, nofollow, noarchive, nosnippet, none";
expires 5m;
max_ranges 0;
header_filter_by_lua_block {
local pcre = require "pcre"
if ngx.var.http_accept_language == nil then
return ngx.exit(403)
elseif ngx.var.http_user_agent == nil then
return ngx.exit(403)
elseif ngx.var.http_accept_encoding == nil then
return ngx.exit(403)
elseif pcre.find(ngx.var.http_accept_encoding, '\\bbr\\b') == nil then
return ngx.exit(403)
else
local ua = ngx.var.http_user_agent
if pcre.find(ua, '^(Mozilla|Opera)/') == nil then
return ngx.exit(403)
elseif pcre.find(ua, '\\bhttps?://') ~= nil then
return ngx.exit(403)
end
end
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment