Last active
April 28, 2021 20:38
-
-
Save Xachman/eb40384f2cf9bb5c92e6a37ff256396e to your computer and use it in GitHub Desktop.
nginx fail2ban block ip action
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
# | |
# add the include to the location or locations you want to deny access to | |
# location ... { | |
# include /etc/nginx/conf.d/denyips; | |
# ... | |
# } | |
# | |
# | |
[Definition] | |
srv_cfg_path = /etc/nginx/ | |
srv_cmd = nginx | |
deny_lst_reload = %(srv_cmd)s -qt; if [ $? -eq 0 ]; then | |
%(srv_cmd)s -s reload; if [ $? -ne 0 ]; then echo 'reload failed.'; fi; | |
fi; | |
deny_lst_file = %(srv_cfg_path)sconf.d/denyips | |
actionstart_on_demand = false | |
actionstart = touch '%(deny_lst_file)s' | |
actionflush = truncate -s 0 '%(deny_lst_file)s'; %(deny_lst_reload)s | |
actionstop = %(actionflush)s | |
actioncheck = | |
_echo_deny_row = printf 'deny %%s;\n' "<fid>" | |
actionban = %(_echo_deny_row)s >> '%(deny_lst_file)s'; %(deny_lst_reload)s | |
actionunban = id=$(%(_echo_deny_row)s | sed -e 's/[]\/$*.^|[]/\\&/g'); sed -i "/^$id$/d" %(deny_lst_file)s; %(deny_lst_reload)s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment