简体   繁体   English

NodeJS部署到AWS Beanstalk的错误

[英]NodeJS Deployment to AWS Beanstalk errors

I've stumbled upon some issues when deploying to AWS beanstalk. 部署到AWS Beanstalk时,我偶然发现了一些问题。 At first I thought the problem is with my Node.js app, but then I've tried clean install. 起初,我认为问题出在我的Node.js应用程序上,但后来我尝试了全新安装。 I've created blank Node.js Express app with WebStorm. 我已经使用WebStorm创建了空白的Node.js Express应用程序。 Created new Application at AWS Beanstalk running on nginx 1.6.2 Then I zip my app and deploy it through Beanstalk console. 在nginx 1.6.2上运行的AWS Beanstalk上创建了新应用程序,然后我将应用程序压缩并通过Beanstalk控制台进行部署。 Upload completes successfully, however when I run application i get 502 bad gateway. 上传成功完成,但是当我运行应用程序时,我得到502错误的网关。 I've tried to change the default port since Web Storm creates app running on port 3000, so I've changed it to 8081. But i still get the error. 由于Web Storm创建了在端口3000上运行的应用程序,因此我尝试更改默认端口,因此我将其更改为8081。但是仍然出现错误。 When looking up for error in logs I've got the following. 在日志中查找错误时,我得到了以下内容。

/var/log/nodejs/nodejs.log /var/log/nodejs/nodejs.log

at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/app/current/app.js:8:14)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)module.js:340
throw err;

Error: Cannot find module '/var/app/current/routes/index'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/var/app/current/app.js:8:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

module.js:340

It's clear that the problem is because node fails to find modules because of the relative path so I changed all entries with relative paths to use absolute path. 显然,问题是因为节点由于相对路径而无法找到模块,因此我将所有具有相对路径的条目更改为使用绝对路径。 for Example 例如

var app = require('../app');

I've changed to 我已更改为

var path = require('path');
var app = require(path.join(__dirname, '../app'));

Still I get the same error. 仍然我得到同样的错误。

Also I get the following error in nginx log: 我也在nginx日志中得到以下错误:

/var/log/nginx/error.log /var/log/nginx/error.log

-------------------------------------
2014/12/05 14:28:35 [error] 23444#0: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.25.31, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "nodesampleapp-env.elasticbeanstalk.com"

Any idea why this is happening? 知道为什么会这样吗? Appreciate any help. 感谢任何帮助。

fix your package.js! 修复您的package.js!

In my case, the node file name was wrong. 就我而言,节点文件名错误。

{
  "name": "your application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": 
    {
      "start": "node app_bot.js"
    },

    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM