在 Elastic Beanstalk 部署期间是否覆盖了 Nginx 配置文件? [英] Nginx config file overwritten during Elastic Beanstalk deployment?

查看:29
本文介绍了在 Elastic Beanstalk 部署期间是否覆盖了 Nginx 配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将 p3p 标头添加到标准 Nodejs 上的静态资源位置 &Nginx 弹性豆茎.

I need to add p3p headers to the static resource location on a standard Nodejs & Nginx Elastic Beanstalk.

我创建了一个 ebextension 脚本,如 这个问题.该脚本使用 set 在 alias 行下添加一个 add_header 指令,该指令位于 static location 指令下.它在 /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf 文件上运行.

I've created an ebextension script as explained on this question. The script uses set to add a add_header directive under the alias line, which is under the static location directive. It runs on the /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf file.

该脚本不仅会修改文件,还会将其复制到保险箱"中.位置,即/home/ec2-user.根据 /var/log/cfn-init.log,脚本运行正常.作为证据,修改后的文件副本在正确的位置显示了附加标题.但是/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf文件没有这个修改.

The script not only modifies the file, it also copies it to a "safe" location, i.e. /home/ec2-user. According to /var/log/cfn-init.log, the script runs correctly. As evidence, the copy of the modified file shows the additional header at the right place. But the /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf file does not have this modification.

我只能推断,虽然我的脚本运行良好,但部署过程中的其他内容会覆盖它.这很奇怪,因为 根据文档容器命令是在应用程序和网络服务器设置后运行的,所以我看不到它是做什么的.

I can only deduce that although my script runs fine, something else later in the deployment process overwrites it. Which is strange, because according to documentation container commands are run after the application and web server have been set up, so I don't see what does it.

那么/什么正在覆盖这个文件,我该如何防止?

So ho/what is overwriting this file and how can I prevent that?

推荐答案

Elastic Beanstalk 似乎发生了变化,通常推荐的覆盖方法/hack 覆盖 #etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf 不再起作用.也不会在/tmp/deployment/config 中创建任何文件.

It seems that Elastic Beanstalk has changed and the commonly recommended approach/hack of overwriting #etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf doesn't work any more. Nor does creating any file in /tmp/deployment/config.

我找到的解决方案是使用 container_commands 指令直接覆盖 /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf,因为这些命令是在 Elastic Beanstalk 安装创建它的 nginx 配置版本之后执行的.

The solution I found was to overwrite /etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf directly, using a container_commands directive, since these commands are executed after the Elastic Beanstalk install creates it's version of the nginx config.

来自 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#linux-container-commands:

它们 [container_commands] 在设置应用程序和 Web 服务器并提取应用程序版本文件之后,但在部署应用程序版本之前运行.

They [container_commands] run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed.

我在 .ebextensions 中分三步完成:

I did this in three steps within .ebextensions:

  1. 创建我的 nginx 配置文件版本.

  1. Create my version of the nginx config file.

创建一个脚本,用我自己的脚本覆盖标准配置文件.

Create a script to overwrite the standard config file with my own.

运行脚本.

前两个步骤发生在安装过程的较早阶段,而最后一个步骤使用 container_commands,因此如前文所述,发生在安装过程的后期.

The first two steps happen earlier in the install process, while the last uses container_commands so as described previous happens late in the install.

这是我使用的文件:

文件 .ebextensions/install_nginx_config_01.config:
(注意缩进很重要)

File .ebextensions/install_nginx_config_01.config:
(Note that the indenting is important)

#
#   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"

这篇关于在 Elastic Beanstalk 部署期间是否覆盖了 Nginx 配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆