我正在尝试将本地开发的Web应用程序部署为AWS实例。该应用程序基于Web,后端为node.js。我使用aws的Elastic Beanstalk上传了该应用程序,它非常简单并且运行良好。部署完成后,我收到了绿色的健康复选标记。
但是,当我选择仪表板顶部的URL来打开新部署的应用程序时,出现了“ 502 Bad Gateway”错误。我进行了一次Google搜索,以查明错误是什么,以及如何纠正错误,但没有成功。大部分建议是刷新页面,并且以某种方式“自行”消失。没有。我还阅读了Elastic Beanstalk战争-502 Bad Gateway stackoverflow问题,也没有获得太大的成功。
这是我从aws下载的error.log的输出:
2018/10/11 15:04:24 [error] 2946#0: *231 connect() failed (111:
Connection refused) while connecting to upstream, client: 172.31.88.17,
server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/",
host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com"
2018/10/11 15:04:24 [error] 2946#0: *231 connect() failed (111:
Connection refused) while connecting to upstream, client: 172.31.88.17,
server: , request: "GET /favicon.ico HTTP/1.1", upstream:
"http://127.0.0.1:8081/favicon.ico", host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com", referrer: "http://sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com/"
2018/10/11 15:05:13 [error] 2946#0: *231 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.88.17, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com"
2018/10/11 15:05:13 [error] 2946#0: *231 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.88.17, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com", referrer: "http://sowapp-env.bpcts5p34k.us-east-1.elasticbeanstalk.com/"
我还下载了nodejs.log,它似乎表明aws服务器未指向启动文件server.js。
Error: Cannot find module '/var/app/current/system.js'
at Function.Module._resolveFilename (module.js:476:15)
at Function.Module._load (module.js:424:25)
at Module.runMain (module.js:611:10)
at run (bootstrap_node.js:394:7)
at startup (bootstrap_node.js:160:9)
at bootstrap_node.js:507:3
module.js:478
throw err;
建议表示赞赏。
谢谢...
答案 0 :(得分:1)
我会尝试的。 在源中设置一个文件夹,将其上传到名为.ebextensions的弹性beantalk中 在此处创建文件以设置源并设置应用程序。
一个示例正在创建一个名为node-settings.config的文件 (要运行您的应用程序需要初始化的所有npm命令),示例\ /来自链接:
option_settings:
aws:elasticbeanstalk:container:nodejs:
NodeCommand: "npm start"
ProxyServer: apache
GzipCompression: true
aws:elasticbeanstalk:container:nodejs:staticfiles:
/images: myimages
这里是链接,显示您可以在此文件(nodejs)中设置为平台特定选项的内容: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/command-options-specific.html
答案 1 :(得分:0)
就我而言,我尝试将node.js端口更改为8081并在本地分支上提交。之后通过命令行部署进行 eb部署解决了我的问题。