'Not Acceptable' page generated by Mod_Security
Not Acceptable!Short answer
ModSecurity matched a rule against your request and denied it, so Apache never reached PHP. Find the rule ID in the audit or error log, then remove that one rule for that one location with SecRuleRemoveById, or test with DetectionOnly. Do not switch the whole engine off.
Fix it fast
1Find out which cause you have
Find the ModSecurity entry for the blocked request. It names the rule id that matched.
sudo grep -i "modsecurity" /var/log/apache2/error.log | tail -n 202Match what you see, then jump to its fix
What does the error look like?
Not Acceptable!An appropriate representation of the requested resource could not be found on this server. This error was generated by Mod_Security.
Cause 1 of 2
A single rule matched your legitimate request
1Check
Note the id from the log. ModSecurity rules need a numeric id, and the audit log (SecAuditLog) records the full request.
sudo grep -ri "SecAuditLog" /etc/modsecurity /etc/apache2 2>/dev/null2Fix
Remove that rule for the context that needs it, in a location or virtual host block rather than globally. SecRuleRemoveById takes rule ids.
<LocationMatch "^/admin/save\.php$">
SecRuleRemoveById 100001 # example id: use the id from your log
</LocationMatch>3Verify
Test the config, reload Apache and repeat the request.
sudo apachectl configtest && sudo systemctl reload apache2Confirmed by github.com
Cause 2 of 2
You are not sure which rule is responsible
1Check
SecRuleEngine can run in DetectionOnly, where rules are processed and logged but disruptive actions such as deny are not executed.
grep -rn "SecRuleEngine" /etc/modsecurity /etc/apache2 2>/dev/null2Fix
Switch to DetectionOnly for a short test on a non-production host, make the request, read which ids log, then remove only those rules and switch back to On.
SecRuleEngine DetectionOnly3Verify
The request passes while the log still lists the matching ids.
sudo grep -i modsecurity /var/log/apache2/error.log | tail -n 20Confirmed by github.com
How do I stop it coming back?
- Remove rules by id and by location, never the whole engine.
- Keep a comment next to each SecRuleRemoveById saying what request it unblocks.
- Re-test after every ModSecurity rule set update, since ids can change.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Related fixes
Servers
Status code 460 on an AWS Application Load Balancer
elb_status_code 460 in ALB access logs
A 460 is generated by the load balancer, not by your app.
3 causes, each with a fixServers
Application Load Balancer returns 504 for requests to EC2 instances
HTTPCode_ELB_504_Count
A 504 from an Application Load Balancer means it could not get an answer from a target in time.
4 causes, each with a fixServers
apk cannot find py-pip in an Alpine Docker image
py-pip (no such package):
On current Alpine releases there is no package called py-pip.
2 causes, each with a fixServers
dnf cannot install MySQL on Amazon Linux 2023
dnf cannot find a mysql-server package on Amazon Linux 2023
Amazon Linux 2023 documents MariaDB, not MySQL, as its database server, with packages named mariadb105 and mariadb105-server.
3 causes, each with a fixServers
ng serve runs in the container but localhost:4200 does not open
The browser cannot open localhost:4200 although ng serve is running in the container
ng serve listens on localhost by default, which inside a container is the container itself.
3 causes, each with a fixServers
Angular routes return 404 from nginx when you refresh or open a link
The home page loads, but refreshing /some/route shows an nginx 404
Angular routes like /users/42 are not files, so nginx looks for them on disk and returns 404.
3 causes, each with a fix