在弹性beantalk上自定义nginx.conf [英] Customizing nginx.conf on elastic beanstalk
问题描述
我需要在/etc/nginx/nginx.conf
文件中自定义keepalive_timeout
设置,该文件在弹性beantalk ec2实例上当前默认为65
.
I need to customize keepalive_timeout
settings in /etc/nginx/nginx.conf
file which defaults to 65
currently on elastic beanstalk ec2 instance.
我遵循了以下说明,但是当我部署新代码时,我得到了Nginx错误,例如:
I followed the following description but when I deploy new code I get nginx error like:
[emerg] 4551#0:"keepalive_timeout"指令是 在/etc/nginx/conf.d/proxy.conf:2中重复
[emerg] 4551#0: "keepalive_timeout" directive is duplicate in /etc/nginx/conf.d/proxy.conf:2
稍后,我尝试使用sed直接更新nginx.conf
Later I tried to directly update nginx.conf using sed as follow
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
文件的正确方法.我尝试了类似的东西
这给了我这样的错误:
Which is not working again (value is not replaced). So I am looking for proper way to update/customize nginx.conf
file. I tried something like this
which gives me an error like:
Service:AmazonCloudFormation, 消息:[/资源/AWSEBAutoScalingGroup/元数据/AWS::CloudFormation::Init/prebuild_0_appname/files//opt/elasticbeanstalk/#etc#nginx#custom-nginx.conf] 模板中不允许使用'null'值
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
路线,则命令应改为:
If you want to go this sed
route, the command should be this instead:
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
)的位置.
That's the location of the actual nginx.conf
(and others, like e.g. 00_elastic_beanstalk_proxy.conf
) that Beanstalk uses to replace the default file.
不需要02_restart_nginx
命令,您可以删除该命令(自19年8月起).
There is no need for the 02_restart_nginx
command, you can remove that one (as of Aug'19).
我在Beanstalk env上使用在64位Amazon Linux/4.8.2上运行的Node.js对此进行了测试.总体而言,它看起来有些黑,您可能想向AWS支持咨询有关自定义nginx.conf的官方"方法.
I tested this on Beanstalk env with Node.js running on 64bit Amazon Linux/4.8.2. Overall though, it looks a bit hacky, you may want to consult with AWS support for the "official" way to customize nginx.conf.
这篇关于在弹性beantalk上自定义nginx.conf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!