Elastic Beanstalk 似乎发生了变化,通常推荐的覆盖#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf 的方法/hack 不再有效。也不会在 /tmp/deployment/config 中创建 任何 文件。
我找到的解决方案是使用 container_commands 指令直接覆盖 /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf,因为这些命令是在 Elastic Beanstalk 安装创建它的 nginx 版本之后执行的配置。
来自http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-container-commands:
它们 [container_commands] 在设置应用程序和 Web 服务器并提取应用程序版本文件之后,但在部署应用程序版本之前运行。
我在 .ebextensions 中分三个步骤完成此操作:
创建我的 nginx 配置文件版本。
创建一个脚本来用我自己的覆盖标准配置文件。
运行脚本。
前两个步骤发生在安装过程的较早阶段,而最后一个步骤使用 container_commands,因此如前所述,发生在安装过程的后期。
这是我使用的文件:
文件 .ebextensions/install_nginx_config_01.config:
(注意缩进很重要)
#
# STEP 1 - Create the nginx config file
#
files:
"/tmp/my.nginx.conf" :
mode: "000755"
owner: root
group: root
content: |
# This file was overwritten during deployment
# by .ebextensions/install_nginx_config_03.config
upstream nodejs {
server 127.0.0.1:3000;
keepalive 256;
}
server {
listen 8080;
location / {
proxy_pass http://nodejs;
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;
}
gzip on;
gzip_comp_level 4;
gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
}
文件 .ebextensions/install_nginx_config_02.config:
#
# STEP 2 - Create a script that will overwrite the Nginx config
#
files:
"/tmp/install-nginx-config.sh" :
mode: "000755"
owner: root
group: root
content: |
#!/bin/sh
cp /tmp/my.nginx.conf /tmp/deployment/config/#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf
文件 .ebextensions/install_nginx_config_03.config:
#
# STEP 3 - Run the script to overwrite the nginx config template.
#
container_commands:
01_runmyshellscript:
command: "/tmp/install-nginx-config.sh"