简体   繁体   English

Elastic Beanstalk Nginx代理抛出502 Bad Gateway

[英]Elastic Beanstalk nginx proxy throwing 502 Bad Gateway

I have a simple MEAN application, which I compose using a Mongo image and a Node + Express image. 我有一个简单的MEAN应用程序,它使用Mongo图像和Node + Express图像组成。 I use Elastic Beanstalk to create a Docker Application. 我使用Elastic Beanstalk创建Docker应用程序。 I am able to create an environment successfully. 我能够成功创建一个环境。 EB dashboard tells me that both the application and the environment were successfully created. EB仪表板告诉我,应用程序和环境均已成功创建。

However the URL for my EB instance gives me a 502 Bad Gateway. 但是,我的EB实例的URL给了我502错误的网关。 I researched this error in relation to Beanstalk and variously tried: 我研究了有关Beanstalk的错误,并尝试了多种方法:

None of these approaches worked. 这些方法均无效。

My Dockerfile 我的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": [
 ]
}

Relevant bits of my package.json 我的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"
  }

Relevant bits of my server.js 我的server.js相关位

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

I also found an answer on SO that suggested overriding the nginx.conf before Beanstalk sets it. 我还在SO上找到了一个答案,建议在Beanstalk设置它之前覆盖nginx.conf I was able to download logs from EB and they are as follows: 我能够从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/"

I would appreciate any pointers as to where to start looking for potential causes of the error. 我希望您能从哪里开始寻找错误的潜在原因。

Had a similar issue myself, and the problem was that nginx connects to node.js on port 8081 by default. 我本人也遇到过类似的问题,问题是nginx默认情况下在端口8081上连接到node.js。 I can see in your code that you're trying to listen on port 3000 by default. 我可以在您的代码中看到默认情况下您尝试监听端口3000。

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

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