【问题标题】:AWS Elastic Beanstalk with docker-compose.ymlAWS Elastic Beanstalk 与 docker-compose.yml
【发布时间】:2021-09-20 11:45:09
【问题描述】:

我正在尝试使用AWS Elastic BeanstalkDocker running on Amazon Linux 2 平台部署多个服务。 因为,我的docker-compose.yml 文件中有两个服务:

version: '3.8'
services:
  beanstalk-flask:
    image: "anotheruserdocker/beanstalk-flask"
    ports:
      - "5000:5000"
  tasks:
    image: "xxxxx.dkr.ecr.us-east-1.amazonaws.com/xxx:xxx"
    ports:
      - "8080:8080"

我需要更改 nginx 服务配置,以便将流量代理到特定服务。
我正在关注documentation,其中注意到您可以用自己的方式覆盖默认的nginx.conf,为了做到这一点,您需要将配置文件放在application source bundle 中,就像.platform/nginx/nginx.conf .
我还包含了这个 include conf.d/elasticbeanstalk/*.conf; 行以覆盖它。
nginx.conf 文件:

# Elastic Beanstalk Nginx Configuration File

user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;
worker_rlimit_nofile    32633;
include conf.d/elasticbeanstalk/*.conf;

upstream service_1 {
    server 172.17.0.1:8080;
    keepalive 256;
}

upstream serivce_2 {
    server 172.17.0.1:5000;
    keepalive 256;
}

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    access_log    /var/log/nginx/access.log;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';

    include  conf.d/*.conf;

    map $http_upgrade $connection_upgrade {
            default       "upgrade";
    }

    server {
        listen 80 default_server;
        gzip on;
        gzip_comp_level 4;
        gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

        access_log    /var/log/nginx/access.log main;

        location / {
            proxy_pass            http://service_1;
            proxy_http_version    1.1;

            proxy_set_header    Connection             $connection_upgrade;
            proxy_set_header    Upgrade                $http_upgrade;
            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 /api {
            proxy_pass            http://service_2;
            proxy_http_version    1.1;
        }

        # Include the Elastic Beanstalk generated locations
        include conf.d/elasticbeanstalk/*.conf;
    }
}

一旦我上传了应用程序source bundle,看起来像这样:

docker-compose.yml
.platform/nginx/nginx.conf

配置没有改变。
我是否遗漏了什么,是错误,还是有任何其他方法可以更改/修改默认 nginx 配置?
另外,我注意到启动时nginx.service 不处于运行状态,是否可以在启动时启动此服务?
谢谢。

【问题讨论】:

    标签: amazon-web-services docker-compose amazon-elastic-beanstalk nginx-reverse-proxy


    【解决方案1】:

    找到了可能的解决方案。

    在创建AWS Elastic Beanstalk 环境期间(如果您使用的是负载均衡部署类型),您可以添加负载均衡器将注册的进程(?)。

    添加进程(在80805000 端口上运行)后,我为侦听端口5000 上的流量的应用程序负载均衡器创建了额外的listener(我这样做只是为了此端口,因为默认情况下AWS Elastic Beanstalk 环境会创建一个侦听器,该侦听器将流量转发到在指定8080 端口上运行的 EC2 实例的目标组)并将其转发到在此端口上运行它的进程的目标组.

    完成这些步骤后,它起作用了。

    有趣的是,我真的不知道它是如何工作的,我已经连接到 EC2 实例并注意到 nginx.service 处于 inactive 状态。

    可能我不清楚这在幕后是如何工作的,任何澄清将不胜感激。

    谢谢!

    P.S.:一旦我获得足够的声望点,我会附上一些步骤的截图。

    【讨论】:

      【解决方案2】:

      Nginx 服务根本没有配置。使用 AWS Elastic Beanstalk 和在 Amazon Linux 2 + docker compose 上运行的 Docker,他们假设您在容器中运行 Nginx。

      记录在这里:https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker.container.console.html#docker-software-config

      【讨论】:

        猜你喜欢
        • 2021-07-11
        • 2021-05-01
        • 1970-01-01
        • 2020-05-03
        • 2019-02-13
        • 2017-07-26
        • 2015-09-15
        • 2015-05-01
        • 2014-12-22
        相关资源
        最近更新 更多