【问题标题】:AWS Elastic Beanstalk deployment 502 Gateway ErrorAWS Elastic Beanstalk 部署 502 网关错误
【发布时间】:2017-12-09 23:49:35
【问题描述】:

我将单个 Docker 容器部署到 AWS Elastic Beanstalk。

当我访问该站点时,它返回一个502错误,这让我认为Docker容器内的端口没有暴露。

这些是我的设置:

Dockerrun.aws.json:

{
"AWSEBDockerrunVersion": "1",
"Volumes": [
  {
    "ContainerDirectory": "/var/app",
    "HostDirectory": "/var/app"
  }
],
"Logging": "/var/eb_log",
"Ports": [
  {
    "containerPort": 80
  }
]
}

Dockerfile

FROM ubuntu:16.04

# Install Python Setuptools
RUN rm -fR /var/lib/apt/lists/*
RUN apt-get update
RUN apt-get install -y software-properties-common
RUN add-apt-repository ppa:jonathonf/python-3.6
RUN apt-get update && apt-get install -y python3-pip
RUN apt-get install -y python3.6
RUN apt-get install -y python3-dev
RUN apt-get install -y libpq-dev
RUN apt-get install libffi-dev
RUN apt-get install -y git

# Add and install Python modules
ADD requirements.txt /src/requirements.txt
RUN cd /src; pip3 install -r requirements.txt

# Bundle app source
ADD . /src

# Expose
EXPOSE  80

# Run
CMD ["python3", "/src/app.py"]

app.py

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
    return "Hello World!"

# run the app.
if __name__ == "__main__":
    # Setting debug to True enables debug output. This line should be
    # removed before deploying a production app.
    app.debug = False
    app.run(port=80)

我在 docker-ps.log 中看到了这个:

CONTAINER ID        IMAGE               COMMAND                 CREATED             
STATUS              PORTS               NAMES
ead221e6d2c6        2eb62af087be        "python3 /src/app.py"   34 minutes ago      Up 34 minutes       80/tcp              peaceful_lamport

和:

/var/log/eb-docker/containers/eb-current-app/ead221e6d2c6-stdouterr.log
-------------------------------------
* Running on http://127.0.0.1:80/ (Press CTRL+C to quit)

这个错误:

2017/07/06 05:57:36 [error] 15972#0: *10 connect() failed (111: Connection refused) while connecting to upstream, client: 172.5.154.225, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.3:80/", host: "bot-platform.us-west-2.elasticbeanstalk.com"

我做错了什么?

【问题讨论】:

    标签: amazon-web-services amazon-elastic-beanstalk


    【解决方案1】:

    查看您的错误代码后,我认为您可以尝试以下解决方案。看来您必须编辑弹性豆茎的 nginx 配置。为此,您将文件 nginx.config 添加到弹性 beanstalk 中的目录 .ebextionsions 中。将以下内容放入文件中:

    files:
      "/etc/nginx/conf.d/000_my_config.conf":
      content: |
        upstream nodejsserver {
          server 127.0.0.1:8081;
          keepalive 256;
        }
    
        server {
          listen 8080;
    
          location / {
            proxy_pass  http://nodejsserver;
            proxy_set_header   Connection "";
            proxy_http_version 1.1;
            proxy_set_header        Host            $host;
            proxy_set_header        X-Real-IP       $remote_addr;
            proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
          }
    
          location /myconfig {
            proxy_pass http://my_proxy_pass_host;
          }
        }
    

    也许您需要稍微调整一下,但这似乎是解决您的问题的正确方法。如果你用谷歌搜索你的错误,你会发现很多关于如何调整 nginx 以解决这个问题的解决方案略有不同。

    【讨论】:

      猜你喜欢
      • 2015-05-04
      • 1970-01-01
      • 2015-04-27
      • 2021-09-16
      • 2022-07-01
      • 2021-03-17
      • 2019-06-12
      • 2019-07-03
      • 2019-02-22
      相关资源
      最近更新 更多