Answer the question
In order to leave comments, you need to log in
How to pass error 500 from node.js (express.js) to nginx?
There is a page of 500s, which is shown in the case of one of the 500s:
error_page 500 501 502 503 504 @500;
location @500 {
internal;
rewrite ^(.*)$ /500;
}
location = /500 {
rewrite ^(.*)$ /500.$lang.html;
}
location ~ /500 {
root $root/500/$bundle;
}
app.get('/503', function(req, res) {
res.status(500).send('internal error');
});
Answer the question
In order to leave comments, you need to log in
Gotta tune it up. By default, nginx does not try to process responses from upstream (from the node) in any way, but simply passes them on to the client. You need the proxy_intercept_errors directive .
Well, your error handling is written strangely.
In general, it should be something like this:
error_page 500 501 502 503 504 @500;
location / {
# проксирование в node
proxy_pass http://127.0.0.1:3000;
proxy_intercept_errors on;
}
location @500 {
# internal не нужен, в именованый location по другому всё равно не попасть
root $root/500/$bundle;
rewrite ^ /500.$lang.html break;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question