According to the documentation the code should be a bit different.
This is the rewriting copied from the documentation:
location /old/path.html {
error_page 404 =301 http:/example.com/new/path.html;
}
Question is if it will work like this:
location 400 {
error_page 400 =307 http:/example.com/400.html;
}
... because on the github-page you linked is written:
If something like "error_page 400 @name" is used in a configuration, a
request could be passed to a named location without URI set, and this
in turn might result in segmentation faults or other bad effects as
most of the code assumes URI is set.
With this change nginx will catch such configuration problems in
ngx_http_named_location() and will stop request processing if URI is
not set, returning 500.
If that's still the current state it would mean a 400 error triggers in nginx a 500 error. Nevertheless I could trigger a 400 error and also deliver a custom 400 page just with this configuration:
error_page 400 /400.html;
So you could also try to configure a custom error 500 page but I never got that running, instead only the common 500er page of nginx was shown.
You can just try it with this configuration
error_page 400 /400.html;
error_page 404 /404.html;
error_page 500 /500.html;
If that's working you can adjust the 3xx code and more like you want it.
Surely you can also deliver the 404 error page on a 400 error, but I never succeeded with rewriting the error headers like this:
error_page 404 =301 http:/example.com/new/path.html;