Enabling custom 403 error docs with nginx in Plesk

Please note that in order to complete these steps you must have admin access to Plesk.

While you would think that enabling “Custom Error Docs” under hosting settings in Plesk, then editing the appropriate document under the /error_docs/ folder in your vhost root would do the trick, unfortunately that’s not the case. Those error documents are seemingly only capable of being loaded by Apache.

If you’ve specified IP allows/denies using Plesk 12+ then it’s using nginx to handle those denies. This is great for performance and resource consumption, but not great when it comes to compatibility with features initially configured for apache use, like custom error documents.

I tried placing the standard error_page directive at every level of the vhost’s nginx config and it did not work anywhere.

The only solution I found that worked was to redirect to an external URL:

error_page 403 = @forbidden;
location @forbidden {
 return 302 http://{secondary_domain}/forbidden.html;
}

If you don’t have another domain to use, the simplest fix is to create a subdomain to enter there, like errors.mydomain.com. Once you have your error doc in the right place (the secondary domain’s web root in the case of the path above), simply insert the abovec code in the domain’s “Additional nginx directives” box (under Apache & Nginx settings). That box is provided only to Plesk admins.

Jordan is a computer, security, and network systems expert and a lover of all things web and tech. Jordan consults with project management for software companies. Jordan is a founder and managing partner at Websavers Inc.

Leave a Comment