Provide possibility to block CIDRs, User-Agents and Referers globally
This commit is contained in:
parent
3f6314aa2f
commit
7212d0081b
6 changed files with 263 additions and 0 deletions
|
|
@ -491,6 +491,28 @@ http {
|
|||
{{ $zone }}
|
||||
{{ end }}
|
||||
|
||||
# Global filters
|
||||
{{ range $ip := $cfg.BlockCIDRs }}deny {{ trimSpace $ip }};
|
||||
{{ end }}
|
||||
|
||||
{{ if gt (len $cfg.BlockUserAgents) 0 }}
|
||||
map $http_user_agent $block_ua {
|
||||
default 0;
|
||||
|
||||
{{ range $ua := $cfg.BlockUserAgents }}{{ trimSpace $ua }} 1;
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if gt (len $cfg.BlockReferers) 0 }}
|
||||
map $http_referer $block_ref {
|
||||
default 0;
|
||||
|
||||
{{ range $ref := $cfg.BlockReferers }}{{ trimSpace $ref }} 1;
|
||||
{{ end }}
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{/* Build server redirects (from/to www) */}}
|
||||
{{ range $hostname, $to := .RedirectServers }}
|
||||
server {
|
||||
|
|
@ -512,6 +534,17 @@ http {
|
|||
{{ end }}
|
||||
server_name {{ $hostname }};
|
||||
|
||||
{{ if gt (len $cfg.BlockUserAgents) 0 }}
|
||||
if ($block_ua) {
|
||||
return 403;
|
||||
}
|
||||
{{ end }}
|
||||
{{ if gt (len $cfg.BlockReferers) 0 }}
|
||||
if ($block_ref) {
|
||||
return 403;
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ if ne $all.ListenPorts.HTTPS 443 }}
|
||||
{{ $redirect_port := (printf ":%v" $all.ListenPorts.HTTPS) }}
|
||||
return {{ $all.Cfg.HTTPRedirectCode }} $scheme://{{ $to }}{{ $redirect_port }}$request_uri;
|
||||
|
|
@ -526,6 +559,18 @@ http {
|
|||
## start server {{ $server.Hostname }}
|
||||
server {
|
||||
server_name {{ $server.Hostname }} {{ $server.Alias }};
|
||||
|
||||
{{ if gt (len $cfg.BlockUserAgents) 0 }}
|
||||
if ($block_ua) {
|
||||
return 403;
|
||||
}
|
||||
{{ end }}
|
||||
{{ if gt (len $cfg.BlockReferers) 0 }}
|
||||
if ($block_ref) {
|
||||
return 403;
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
{{ template "SERVER" serverConfig $all $server }}
|
||||
|
||||
{{ if not (empty $cfg.ServerSnippet) }}
|
||||
|
|
@ -545,6 +590,17 @@ http {
|
|||
{{ if $IsIPV6Enabled }}listen [::]:{{ $all.ListenPorts.Status }} default_server {{ if $all.Cfg.ReusePort }}reuseport{{ end }} backlog={{ $all.BacklogSize }};{{ end }}
|
||||
set $proxy_upstream_name "-";
|
||||
|
||||
{{ if gt (len $cfg.BlockUserAgents) 0 }}
|
||||
if ($block_ua) {
|
||||
return 403;
|
||||
}
|
||||
{{ end }}
|
||||
{{ if gt (len $cfg.BlockReferers) 0 }}
|
||||
if ($block_ref) {
|
||||
return 403;
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
location {{ $healthzURI }} {
|
||||
{{ if $cfg.EnableOpentracing }}
|
||||
opentracing off;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue