我有一个简单的MEAN应用程序,我使用Mongo图像和Node + Express图像进行组合。我使用Elastic Beanstalk创建Docker应用程序。我能够成功创建一个环境。 EB仪表板告诉我,应用程序和环境都已成功创建。
然而,我的EB实例的URL给了我一个502 Bad Gateway。 我研究了与Beanstalk有关的这个错误并尝试了各种方法:
将NodeCommand: "npm start"
属性添加到.ebextensions/node-command.config
,导致Duplicate or Invalid property
错误。
模仿项目的启动方式,详见本回购协议:https://github.com/shippableSamples/sample_node_eb_docker/tree/tutorial
我正在学习本教程; http://blog.shippable.com/how-to-deploy-to-elastic-beanstalk-part-2,以上述项目为例。
基本上,我将app.listen
代码移到bin/www
这些方法都不起作用。
我的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 error.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/"
我很感激任何关于从哪里开始寻找错误的潜在原因的指示。
答案 0 :(得分:0)
我自己也遇到了类似的问题,问题在于nginx默认情况下在端口8081上连接到node.js。我可以在您的代码中看到默认情况下您尝试在端口3000上监听。