Created
March 2, 2022 15:17
-
-
Save ryancdotorg/1b41af4b19ff18d91d717be575ec295d to your computer and use it in GitHub Desktop.
anti-bot nginx snippet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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