Phew, the heading of this post was a mouthful!
This post is a technical one, that probably won't interest many of my regular readers. However I know there are plenty of people looking for how to do this, so I thought I'd post this in case it helps others later.
mod_security is a free or charge module for the Apache webserver. It allows HTTP requests to be analyzed, using a large number of characteristics. You'd be looking for evidence that someone's request to GET or POST is malicious, and you'd block them if so.