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
在撰写本文时,将值更新/添加到文件中的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.conf
http部分拉到nginx.conf
似乎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配置版本之后执行的.
它们[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;
}
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)
截至 2020 年 8 月,对于Ruby 2.6 running on 64bit Amazon Linux 2/3.1.0
:
为我放置nginx
文件.platform/nginx/
。
这是我的文件夹结构:
归档时间: |
|
查看次数: |
9511 次 |
最近记录: |