我已经多次部署了Web应用程序,并且运行良好。
但是自从昨天部署以来,每当我尝试获取网站时,我都会不断收到502 Bad Gateway。
我从AWS Elastic beantalk终止了我的应用程序并重新创建,但仍然遇到502错误的网关。
这是我的nodejs.log:
Error: ENOENT: no such file or directory, open '/var/app/current/config/awsconfig.json'
at Error (native)
at Object.fs.openSync (fs.js:642:18)
at Object.fs.readFileSync (fs.js:510:33)
at Object.readFileSync (/var/app/current/node_modules/aws-sdk/lib/util.js:97:26)
at Config.loadFromPath (/var/app/current/node_modules/aws-sdk/lib/config.js:409:39)
at Object.<anonymous> (/var/app/current/server.js:14:12)
at Module._compile (module.js:577:32)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
fs.js:642
return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
这是我的server.js中与nodejs错误日志相关的部分:
const express = require("express");
const path = require("path");
const fs = require("fs");
const template = require("./public/template");
const bodyParser = require("body-parser");
const _ = require("lodash");
const uuidv1 = require("uuid/v1");
const AWS = require("aws-sdk");
const multer = require("multer");
const multerS3 = require("multer-s3");
// Image Upload
AWS.config.loadFromPath(path.join(__dirname, "/config/awsconfig.json"));
const s3 = new AWS.S3();
const upload = multer({
storage: multerS3({
s3,
bucket: "hackingdeal",
key: (req, file, cb) => {
cb(null, new Date().valueOf() + path.extname(file.originalname));
},
acl: "public-read-write"
})
});
仅供参考,“ server.js”文件位于根目录dir(“ ./ server.js”)中,awsconfig.json位于“ ./config/awsconfig.json”中
我做了一个.gitignore来忽略“ config / awsconfig.json”。 我还创建了一个.ebignore,但是我没有包含“ config / awsconfig.json”,因此我的弹性beantalk可以查找和读取“ config / awsconfig.json”文件。
这是我的nginx / error.log:
2018/10/20 23:32:05 [error] 8103#0: *96 connect() failed (111: Connection refused) while connecting to upstream, client: 110.12.50.169, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "hackingdeal-env.4wgwkb9tdv.ap-northeast-2.elasticbeanstalk.com"
2018/10/20 23:32:05 [error] 8103#0: *96 connect() failed (111: Connection refused) while connecting to upstream, client: 110.12.50.169, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "hackingdeal-env.4wgwkb9tdv.ap-northeast-2.elasticbeanstalk.com", referrer: "http://hackingdeal-env.4wgwkb9tdv.ap-northeast-2.elasticbeanstalk.com/"
2018/10/20 23:48:00 [error] 12936#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 110.12.50.169, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:8081/", host: "hackingdeal.com"
2018/10/20 23:48:01 [error] 12936#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 110.12.50.169, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:8081/favicon.ico", host: "hackingdeal.com", referrer: "http://hackingdeal.com/"
hackingdeal.com是我的网站。我通过使用Route53服务将该域连接到我的Elastic Beanstalk,并创建了别名。
问题是, 我的应用程序在localhost上成功运行。
当我使用图像上传语句部署“ server.js”后,我的应用程序立即成功运行(使用AWS S3和multer / multerS3事情:请参见上面的代码块”
但是从昨天开始,它一直返回502错误的网关。
我完全迷路了,我不知道从哪里开始或在哪里找到我的问题。 请帮助。
答案 0 :(得分:0)
我必须阅读日志以更好地了解您的问题,但看来您尝试从此处的文件/config/awsconfig.json
加载配置
// Image Upload
AWS.config.loadFromPath(path.join(__dirname, "/config/awsconfig.json"));
const s3 = new AWS.S3();
const upload = multer({
storage: multerS3({
s3,
bucket: "hackingdeal",
key: (req, file, cb) => {
cb(null, new Date().valueOf() + path.extname(file.originalname));
},
acl: "public-read-write"
})
});
因此,您必须将此文件上传到ELB。实际上,这就是登录nodejs.log