I'm creating a site with a large number of small tools. One is a tool which uses a Python cgi-script that interacts with the Natural Language Toolkit (nltk), which is disk and CPU intensive. I have other services that are less intensive.
On the client side, these are rate limited with JavaScript throttling. A malicious or dumb user creating a bot could make connections directly. I would like to prevent this at as low of a level as possible, but I need it to be per-directory (the cgi scripts sit next to the index.html files).
I will also have a firewall that blocks abusive IPs making eminence requests. I would like this to return a simple 429 response with an empty JSON object as the body.
I would also like to include other rules in this, like a 30 second receive-to-transmit time, else close the connection.
How can I implement this in a lighttpd server on Debian?