Keeping a self-hosted Forgejo public against AI crawlers, with only Caddy
The author runs a personal Forgejo instance and wants it public, so anyone can browse and clone the open projects. Thousands of home IP addresses each requested a single file at an old commit, at 5 to 10 requests per second, and the server, an Intel Atom N2800 with a spinning hard drive, became unresponsive. In docker stats, Forgejo alone used 118.63% CPU.
Capping the container's CPU only put requests in a queue, and banning IPs did not help, because the scraper rents bandwidth through a residential proxy network[1]. Making the GAMA organisation limited cut the load but hid projects the author wanted public. A first version of a cookie-based Caddy rule did not hold: after the organisation was made public again, bot traffic returned within seconds.
Forgejo also built tarballs[2] of sub-folders at specific commits, each taking 2 to 4 seconds, and cached them on disk, where they reached 2.7 GB. According to the author, the final fix is a couple of lines of Caddy config that block anonymous requests to expensive pages before Forgejo receives them, which brought CPU use from 118% down to 0.3%. The forge stays public, and no Anubis or Cloudflare was put in front of it.
Website Forgejo forgejo.org
Forgejo is a self-hosted, lightweight software forge for hosting git repositories and development work on your own server.
Read the original arthurbrugiere.frDiscussion
Discussion
Commenters mostly suggest other tools: Anubis, which one user kept for a few months until bots started bypassing it before switching to a Cloudflare managed challenge on commit pages; caddy-geoblock for blocking by ASN or region; and rate limiting through the caddy-ratelimit plugin. Another suggests caching anonymous pages with the Souin cache-handler module and letting logged-in users through by checking Forgejo's session cookie. Some ask why the forge needs to be public at all.
Sources
-
arthurbrugiere.fr
Keeping my self-hosted Forgejo public against AI crawlers, with only Caddy





