React+Express+Mongo应用部署至DigitalOcean Ubuntu 20.04服务器后端故障排查求助
React+Express+Mongo应用部署至DigitalOcean Ubuntu 20.04服务器后端故障排查求助
各位好,我现在在把一套React+Express+Mongo的遗留系统部署到DigitalOcean的Ubuntu 20.04服务器上时,后端出现了关键故障,折腾了好久都没解决,希望能得到大家的帮助🙏
部署环境说明
- 服务器:DigitalOcean Ubuntu 20.04 x64,默认配置,未开启防火墙
- 依赖版本:Node.js 14.18.3、MongoDB 4.4(都是项目要求的固定版本,不能升级,因为是遗留系统)
- 运行状态:React前端(3000端口)用pm2托管,能正常显示登录页,功能正常;Express后端(3333端口)同样用pm2托管,但出现异常
具体问题现象
- 接口请求异常
前端调用后端接口失败,为了排除前后端交互的问题,我用Postman直接请求后端的登录接口,依然报错。请求示例:
curl --location --request POST 'http://<ip地址>:3333/auth/login' \ --header 'x-company-id: 1' \ --header 'Content-Type: application/json' \ --data-raw '{ "email": "user@email.com", "password": "123" }'
遇到的错误包括:ERR_TOO_MANY_REDIRECTS、Error: connect ECONNREFUSED
- 端口相关的奇怪表现
- 访问
http://<ip地址>:3333/ping能正常返回pong,说明3333端口没有被阻塞 - 直接访问
http://<ip地址>:3333/时,返回内容是Found. Redirecting to /,出现无意义的重定向
- pm2日志中的错误
后端用pm2运行时,日志抛出了内存相关的错误:
6|backend | npm ERR! code ELIFECYCLE 6|backend | npm ERR! errno 137 6|backend | npm ERR! node-api-dpo@1.0.0 start: `babel-node -- index.js` 6|backend | npm ERR! Exit status 137 6|backend | npm ERR! 6|backend | npm ERR! Failed at the node-api-dpo@1.0.0 start script. 6|backend | npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 6|backend | 6|backend | npm ERR! A complete log of this run can be found in: 6|backend | npm ERR! /root/.npm/_logs/2023-12-09T15_18_09_271Z-debug.log 6|backend | (node:49419) NOTE: We are formalizing our plans to enter AWS SDK for JavaScript (v2) into maintenance mode in 2023. 6|backend | 6|backend | (Use `node --trace-warnings ...` to show where the warning was created)
注:AWS SDK的提示是无关的,因为项目暂时还没升级到v3
- 直接启动后端的错误
如果不用pm2,直接在服务器上运行npm start,会抛出解密相关的错误:
events.js:377 throw er; // Unhandled 'error' event ^ Error: Error during decryption (probably incorrect key). Original error: Error: error:04099079:rsa routines:RSA_padding_check_PKCS1_OAEP_mgf1:oaep decoding error at NodeRSA.module.exports.NodeRSA.$$decryptKey (/root/compassDPO/climby_api_DPO/service/node_modules/node-rsa/src/NodeRSA.js:301:19) at NodeRSA.module.exports.NodeRSA.decrypt (/root/compassDPO/climby_api_DPO/service/node_modules/node-rsa/src/NodeRSA.js:249:21) at Utils.decrypt (/root/compassDPO/climby_api_DPO/service/src/utils/utils.js:454:24) at /root/compassDPO/climby_api_DPO/service/src/oauth/services.js:48:26 at model.Query.<anonymous> (/root/compassDPO/climby_api_DPO/service/node_modules/mongoose/lib/model.js:3932:16) at /root/compassDPO/climby_api_DPO/service/node_modules/kareem/index.js:273:21 at /root/compassDPO/climby_api_DPO/service/node_modules/kareem/index.js:131:16 at processTicksAndRejections (internal/process/task_queues.js:77:11) Emitted 'error' event on Function instance at: at model.Query.<anonymous> (/root/compassDPO/climby_api_DPO/service/node_modules/mongoose/lib/model.js:3934:13) at /root/compassDPO/climby_api_DPO/service/node_modules/kareem/index.js:273:21 at /root/compassDPO/climby_api_DPO/service/node_modules/kareem/index.js:131:16 at processTicksAndRejections (internal/process/task_queues.js:77:11) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! node-api-dpo@1.0.0 babel-node: `babel-node --presets=latest "index.js"` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the node-api-dpo@1.0.0 babel-node script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /root/.npm/_logs/2023-12-10T12_30_45_631Z-debug.log [nodemon] app crashed - waiting for file changes before starting...
已完成的排查动作
- 本地开发环境运行完全正常,没有任何问题
- 重新创建了两次全新的DigitalOcean服务器,从头部署,问题依然存在
- 确认3333端口没有被阻塞:
/ping接口正常响应 - 检查了MongoDB连接,确认服务正常运行,能正常读写数据
- 检查了项目中的
.pem密钥文件,和本地的一致,路径配置也正确
现在我实在想不到还有什么地方可以排查了,有没有朋友遇到过类似的问题?或者有什么排查思路可以推荐?如果需要我做其他测试或者提供更多日志/配置信息,随时告诉我,非常感谢大家的帮助!
备注:内容来源于stack exchange,提问作者Marcos Lemos
相关产品推荐
相关产品推荐

