我正在尝试使用AWS Elastic Beanstalk和Docker 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服务配置,以便将流量代理到特定的服务。
我遵循的是文档,其中指出您可以用自己的nginx.conf覆盖默认的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配置不会改变。
我是不是遗漏了什么,它是一个bug,还是有任何其他方法来更改/修改默认的nginx配置?
另外,我已经注意到,在启动nginx.service时,是否可以在启动时启动该服务?
谢谢。
发布于 2021-09-20 13:08:41
找到了可能的解决方案。
在创建AWS Elastic Beanstalk环境期间(如果使用负载平衡部署类型),可以添加负载均衡器将注册(?)的进程。
一旦我添加了进程(运行在8080和5000端口上),我就为侦听端口5000上的通信量的应用程序负载均衡器创建了额外的listener (我只为这个端口这样做,因为在默认情况下,AWS Elastic Beanstalk环境创建一个侦听器,该侦听器将流量转发给在指定的8080端口上运行的EC2实例的目标组),并将其转发给在此端口上运行该端口的进程的目标组。
做完这些步骤之后,它就成功了。
有趣的是,我真的不知道这是如何工作的,我已经连接到EC2实例,并注意到nginx.service处于inactive状态。
也许我不明白这是如何在幕后工作,任何澄清将不胜感激。
谢谢!
一旦我获得足够的声誉点,我会附上一些所采取步骤的截图。
发布于 2021-10-07 14:19:36
Nginx服务根本没有配置。使用AWS ElasticBean秸秆,在Amazon 2+ Docker上运行docker,它们假设您在容器中运行Nginx。
它被记录在这里:docker.container.console.html#docker-software-config
https://stackoverflow.com/questions/69253869
复制相似问题