【发布时间】:2021-09-20 11:45:09
【问题描述】:
我正在尝试使用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 服务配置,以便将流量代理到特定服务。
我正在关注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