在Elastic Beanstalk部署期间是否覆盖了Nginx配置文件?

Ant*_*ine 11 nginx amazon-web-services amazon-elastic-beanstalk

我需要将p3p标头添加到标准Nodejs和Nginx Elastic Beanstalk上的静态资源位置.

我已经ebextension按照这个问题的解释创建了一个脚本.该脚本使用sed add_header在该alias行下添加一个指令,该指令位于静态位置指令下.它运行在/etc/nginx/conf.d/00_elastic_beanstalk_proxy.conf文件上.

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

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

那么/什么覆盖这个文件,我该如何防止这种情况?

Mon*_*dhi 23

在花了将近一整天并尝试所有可能的解决方案后,截至2017年7月17日,上述解决方案无效.对我来说,我想替换/etc/nginx/conf.d/elasticbeanstalk/00_application.conf我在.ebextension文件夹中创建了下面显示的文件夹结构,文件被我的内容覆盖了.此解决方案也适用于位于/ etc/nginx文件夹中的nginx.conf 在此输入图像描述

  • 谢谢,也为我工作.记录此行为[此处](https://aws.amazon.com/blogs/aws/category/aws-elastic-beanstalk/)._您现在可以在.ebextensions/nginx文件夹中放置一个nginx.conf文件来覆盖Nginx配置.您还可以将配置文件放在.ebextensions/nginx/conf.d文件夹中,以便将它们包含在platform._提供的Nginx配置中. (5认同)
  • 值得一提的是,此解决方案仅适用于某些ELB平台 - Java和Go.如果您使用带有nginx作为代理的Docker平台,则必须使用配置文件(使用**文件**关键字)放在**.ebextensions**中的解决方案 - 例如`files:"/ etc/nginx/nginx .conf":内容:| #your覆盖nginx config here` (4认同)
  • 对于 Ruby Amazon Linux 2,放置在 `./platform/nginx/*` 中是可行的。文档中所述 https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.migration-al.html。 (3认同)
  • 在撰写本文时,我可以确认这不适用于他们最新的节点平台。 (2认同)

McL*_*vin 9

在撰写本文时,将值更新/添加到文件中的http配置而不覆盖它的正确方法是将文件添加到如下所示的文件夹中:nginx.conf.config.ebextensions

files:
  "/etc/nginx/conf.d/custom_nginx.conf":
    content: |

      proxy_connect_timeout       600;
      proxy_send_timeout          600;
      proxy_read_timeout          600;
      send_timeout                600;
Run Code Online (Sandbox Code Playgroud)

这将创建一个custom_nginx.conf/etc/nginx/conf.d目录中调用的新文件.由于nginx.conf文件包含

http {
  include       /etc/nginx/conf.d/*.conf;
}
Run Code Online (Sandbox Code Playgroud)

当服务器启动时,它会将4个超时变量从custom_nginx.confhttp部分拉到nginx.conf

  • 你能帮我如何覆盖 nginx.conf 文件吗?我需要添加 http{underscores_in_headers on;} (2认同)

Phi*_*der 8

似乎Elastic Beanstalk已经改变,通常推荐的覆盖方法/黑客#etc#nginx#conf.d#00_elastic_beanstalk_proxy.conf不再起作用.也没有在/ tmp/deployment/config 中创建任何文件.

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

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

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

我在.ebextensions中分三步完成了这个步骤:

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

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

  3. 运行脚本.

前两个步骤早些时候在安装过程中发生的,而最后使用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;
      }
Run Code Online (Sandbox Code Playgroud)

文件.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
Run Code Online (Sandbox Code Playgroud)

文件.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"
Run Code Online (Sandbox Code Playgroud)

  • 为什么不把`cp`命令放在`container_commands`中? (3认同)

jsh*_*hah 6

截至 2020 年 8 月,对于Ruby 2.6 running on 64bit Amazon Linux 2/3.1.0

为我放置nginx文件.platform/nginx/

这是我的文件夹结构:

在此处输入图片说明

  • 在花了一天时间之后,这是唯一对我有用的事情。`ruby 2.7.1p83(2020-03-31 修订版 a0c7c23c9c)[x86_64-linux] Amazon Linux 2` (2认同)