我有一个 nginx 服务器,它本身处理一些请求,并使用以下几行将其余请求传递到 Node.JS 服务器:
proxy_pass http://localhost:8000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
nginx 和node.js 都会生成自己的http 页面,这些页面应该是相同的(对于用户来说,来自nginx 的404 应该与来自node.js 的404 相同)。
我希望 nginx 检查 Node.js 生成的响应代码,如果产生错误,则返回到它自己的错误页面。这可能或明智吗?
1. Nginx receives HTTP request
2. HTTP request passed to Node.JS
3. Node.JS responds with 404 error
4. Nginx responds with 404 error
最佳答案
添加行
proxy_intercept_errors on;
添加到location block 会导致远程服务器产生的错误被nginx拦截。
关于node.js - 使用 nginx 处理另一台服务器产生的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28114664/