<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Fail2Ban for nginx proxy manager]]></title><description><![CDATA[<p dir="auto">I wan to write an Articlle about this Topic because I havent found one what is including all I want and have to Figure it Out by myself.</p>
<p dir="auto">At first wen need a Folder and get our Docker Compose File running</p>
<pre><code>mkdir fail2ban
cd fail2ban
vi docker-compose.yml
</code></pre>
<p dir="auto">Paste the following text into the editor:</p>
<pre><code>version: "3"

services:
  fail2ban:
    container_name: fail2ban
    hostname: fail2ban
    cap_add:
      - NET_ADMIN
      - NET_RAW
    environment:
      - TZ=Europe/Berlin
      - F2B_DB_PURGE_AGE=14d
      - SSMTP_HOST=&lt;your-mail-server&gt;
      - SSMTP_PORT=25
      - SSMTP_HOSTNAME=&lt;hostname-of-your-container&gt;
    image: crazymax/fail2ban:latest
    network_mode: host
    restart: unless-stopped
    volumes:
      - /root/fail2ban/data:/data
      - /root/ngix-proxy-manager/data/logs:/var/log/npm
      - /var/log:/var/log/varlog

</code></pre>
<p dir="auto">Save the file and start the Container with</p>
<pre><code>docker-compose up -d
</code></pre>
<p dir="auto">The Fail2ban Container will be loaded and is starting. There should be a data dir now with 4 folders</p>
<pre><code>action.d
db
filter.d
jail.d
</code></pre>
<p dir="auto">The db Folder can be ignored, now we need to create a jail.local in jail.d</p>
<pre><code>vi jail.d/jail.local
</code></pre>
<p dir="auto">Paste the following in there.:</p>
<pre><code>[DEFAULT]
# "bantime.increment" allows to use database for searching of previously banned ip's to increase a
# default ban time using special formula, default it is banTime * 1, 2, 4, 8, 16, 32...
bantime.increment = true

# "bantime.rndtime" is the max number of seconds using for mixing with random time
# to prevent "clever" botnets calculate exact time IP can be unbanned again:
bantime.rndtime = 2048

# following example can be used for small initial ban time (bantime=60) - it grows more aggressive at begin,
# for bantime=60 the multipliers are minutes and equal: 1 min, 5 min, 30 min, 1 hour, 5 hour, 12 hour, 1 day, 2 day
bantime.multipliers = 1 5 30 60 300 720 1440 2880

#Ban without sending E-Mail
#action = %(action_)s

#Ban and send E-Mail
action = %(action_mw)s

destemail = &lt;dest email&gt;
sender = &lt;from email&gt;
mta = sendmail

[npm]
# bots that trigger too many 403 or 404
# logs are comming from reverse proxy "nginx proxy manager"
enabled = true
ignoreip = 127.0.0.0/8 10.0.0.0/8 172.0.0.0/8 192.168.0.0/16
filter = npm-filter
chain = DOCKER-USER
logpath = /var/log/npm/proxy-host-*_access.log
maxretry = 5
findtime = 60
bantime = 600

[sshd]

enabled = true
port    = ssh
filter  = sshd
ignoreip = 127.0.0.0/8 10.0.0.0/8 172.27.0.0/16 192.168.0.0/16
chain = INPUT
logpath = /var/log/varlog/auth.log
findtime = 10m
maxretry = 5
bantime = -1

</code></pre>
<p dir="auto">we Monitor the NPM and the Systems sshd here, thats why we mapped the Volume from local logs into the fail2ban container.</p>
<p dir="auto">Next Step is to add filter Rules in filter.d for our NPM</p>
<pre><code>vi filter.d/npm-filter.conf
</code></pre>
<pre><code>[INCLUDES]

[Definition]

failregex = ^.+ (405|404|403|401|\-) (405|404|403|401) - .+ [Client &lt;HOST&gt;] [Length .+] .+ [Sent-to &lt;F-CONTAINER&gt;.+&lt;/F-CONTAINER&gt;] &lt;F-USERAGENT&gt;".+"&lt;/F-USERAGENT&gt; .+$

ignoreregex = ^.+ (404|\-) (404) - .+".+(\.png|\.txt|\.jpg|\.ico|\.js|\.css)[/]" [Client &lt;HOST&gt;] [Length .+] ".+" .+$
</code></pre>
<p dir="auto">Now we have everything set up and we can restart the container with</p>
<pre><code>docker-compose restart
</code></pre>
<p dir="auto">Now we want to see what fail2ban is doing. We can check the logs by doing docker ps to show the running containers and docker logs &lt;container-id&gt; --follow</p>
<p dir="auto">Thats it, feel Free to ask if you have problems with this Setup</p>
]]></description><link>https://forum.its-egner.de/topic/45/fail2ban-for-nginx-proxy-manager</link><generator>RSS for Node</generator><lastBuildDate>Wed, 15 Apr 2026 11:19:55 GMT</lastBuildDate><atom:link href="https://forum.its-egner.de/topic/45.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 04 Jan 2023 09:58:26 GMT</pubDate><ttl>60</ttl></channel></rss>