gpt4 book ai didi

node.js - Elastic Beanstalk nginx 代理抛出 502 Bad Gateway

转载 作者:太空宇宙 更新时间:2023-11-04 02:03:01 25 4
gpt4 key购买 nike

我有一个简单的 MEAN 应用程序,我使用 Mongo 图像和 Node + Express 图像组成。我使用 Elastic Beanstalk 创建 Docker 应用程序。我能够成功创建一个环境。 EB 仪表板告诉我应用程序和环境均已成功创建。

但是,我的 EB 实例的 URL 给出了 502 Bad Gateway。我研究了与 Beanstalk 相关的此错误并进行了各种尝试:

这些方法都不起作用。

我的Dockerfile

FROM node:7
RUN mkdir -p /usr/src/rishighan

WORKDIR /usr/src/rishighan

COPY package.json /usr/src/rishighan
COPY bower.json /usr/src/rishighan

#Install dependencies
RUN npm i -g bower && \
npm i && \
bower i --config.interactive=false --allow-root

RUN npm rebuild node-sass

COPY . /usr/src/rishighan
EXPOSE 80

# This starts the app
CMD npm start

docker-compose.yml

# find a way to seed the mongo db
version: '3.2'
services:
mongodb:
build:
context: ./
dockerfile: mongo-seed/Dockerfile
web:
build: .
command: node server.js
volumes:
- .:/usr/src/rishighan
ports:
- "3000:3000"
links:
- mongodb
environment:
PORT: 3000 # this is optional, allows express to use process.env.PORT instead of a raw 3000

Dockerrun.aws.json

 {
"AWSEBDockerrunVersion": "1",
"Image": {
"Name": "frishi/rishighanangular_web:nativeEBDeployment",
"Update": "true"
},
"Ports": [
{
"ContainerPort": "80"
}
],
"Volumes": [
]
}

我的package.json的相关部分

  "scripts": {
"dev": "webpack-dev-server --content-base app/ --hot --inline",
"start": "webpack -w --debug --devtool eval --output-pathinfo",
"local-dev": "node server.js",
"test": "testem ci"
}

我的server.js的相关部分

// Start Server on 3000
let port = process.env.PORT || 3000;
app.listen(port, function () {
console.log("Server listening on port ", port);
});

我还在 SO 上找到了一个答案,建议在 Beanstalk 设置之前覆盖 nginx.conf 。我能够从 EB 下载日志,如下所示:

nginx错误.log

2017/07/24 12:10:47 [error] 3378#0: *8824 connect() failed (111: Connection refused) while connecting to upstream, client: 10.65.133.248, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:80/", host: "54.243.122.6"
2017/07/24 13:27:16 [error] 3378#0: *9903 connect() failed (111: Connection refused) while connecting to upstream, client: 10.164.151.69, server: , request: "GET /xmlrpc.php HTTP/1.1", upstream: "http://172.17.0.2:80/xmlrpc.php", host: "54.197.241.240"
2017/07/24 13:29:18 [error] 3378#0: *9946 connect() failed (111: Connection refused) while connecting to upstream, client: 10.164.151.69, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:80/", host: "54.197.241.240"
2017/07/24 14:17:28 [error] 3378#0: *10615 connect() failed (111: Connection refused) while connecting to upstream, client: 10.65.133.248, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:80/", host: "rishighan-angular-dev.us-east-1.elasticbeanstalk.com"
2017/07/24 14:17:28 [error] 3378#0: *10615 connect() failed (111: Connection refused) while connecting to upstream, client: 10.65.133.248, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://172.17.0.2:80/favicon.ico", host: "rishighan-angular-dev.us-east-1.elasticbeanstalk.com", referrer: "http://rishighan-angular-dev.us-east-1.elasticbeanstalk.com/"

如果您能指出从哪里开始寻找错误的潜在原因,我将不胜感激。

最佳答案

我自己也有类似的问题,问题是nginx默认连接到端口8081上的node.js。我可以在您的代码中看到您默认尝试监听端口 3000。

关于node.js - Elastic Beanstalk nginx 代理抛出 502 Bad Gateway,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45283983/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com