Funny, I literally just did this for nginx. In case anyone needs it:
server {
...
fastcgi_intercept_errors on; # without this call it wouldn't serve my custom error pages
error_page 401 @401;
location @401 {
root /srv/www/error-documents/public;
try_files /401.html =401;
}
error_page 403 @403;
location @403 {
root /srv/www/error-documents/public;
try_files /403.html =403;
}
error_page 404 @404;
location @404 {
root /srv/www/error-documents/public;
try_files /404.html =404;
}
error_page 408 @408;
location @408 {
root /srv/www/error-documents/public;
try_files /408.html =408;
}
error_page 500 @500;
location @500 {
root /srv/www/error-documents/public;
try_files /500.html =500;
}
error_page 502 @502;
location @502 {
root /srv/www/error-documents/public;
try_files /502.html =502;
}
error_page 503 @503;
location @503 {
root /srv/www/error-documents/public;
try_files /503.html =503;
}
}