Using ModSecurity
OWASP CRS automatically blocks SQLi patterns. Create custom rule:
SecRule ARGS "@rx (?i)(select|union|insert|update|delete|drop|--)" "id:1000,phase:2,deny,status:403,msg:'SQL Injection Detected'"Using Nginx Native (without ModSecurity)
location ~* (select|union|insert|update|delete) {
return 403;
}Application-Level Protection
Use prepared statements and parameterized queries in your code.
Test with sqlmap (authorized only)
sqlmap -u "http://example.com/page?id=1" --batch