我需要在 /etc/nginx/nginx.conf
文件中自定义 keepalive_timeout
设置,该设置当前在 Elastic beanstalk ec2 实例上默认为 65
。
我关注了following描述,但是当我部署新代码时,我收到 nginx 错误,如下所示:
[emerg] 4551#0: "keepalive_timeout" directive is duplicate in /etc/nginx/conf.d/proxy.conf:2
后来我尝试使用 sed 直接更新 nginx.conf,如下
files:
"/etc/nginx/conf.d/proxy.conf" :
mode: "000755"
owner: root
group: root
content: |
client_max_body_size 200M;
client_header_timeout 300;
client_body_timeout 300;
send_timeout 300;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
container_commands:
01_update_nginx:
command: "sudo sed -i 's/keepalive_timeout 65;/keepalive_timeout 360;/g' /etc/nginx/nginx.conf"
02_restart_nginx:
command: "sudo service nginx reload"
这不再起作用(值没有被替换)。所以我正在寻找更新/自定义 nginx.conf 文件的正确方法。我试过something like this 这给了我一个错误,例如:
Service:AmazonCloudFormation, Message:[/Resources/AWSEBAutoScalingGroup/Metadata/AWS::CloudFormation::Init/prebuild_0_appname/files//opt/elasticbeanstalk/#etc#nginx#custom-nginx.conf] 'null' values are not allowed in templates
最佳答案
如果你想走这个 sed
路线,命令应该是这样的:
01_update_nginx:
command: "sudo sed -i 's/keepalive_timeout 65;/keepalive_timeout 360;/g' /tmp/deployment/config/#etc#nginx#nginx.conf"
这是 Beanstalk 用于替换默认文件的实际 nginx.conf
(以及其他文件,例如 00_elastic_beanstalk_proxy.conf
)的位置。
不需要 02_restart_nginx
命令,您可以删除该命令(截至 2019 年 8 月)。
我在 Beanstalk env 上测试了这一点,Node.js 在 64 位 Amazon Linux/4.8.2 上运行。总的来说,它看起来有点老套,您可能需要咨询 AWS 支持以获取自定义 nginx.conf 的“官方”方法。
关于nginx - 在 elastic beanstalk 上自定义 nginx.conf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51421457/