4
votes

I need to customize keepalive_timeout settings in /etc/nginx/nginx.conf file which defaults to 65 currently on elastic beanstalk ec2 instance.

I followed the following description but when I deploy new code I get nginx error like:

[emerg] 4551#0: "keepalive_timeout" directive is duplicate in /etc/nginx/conf.d/proxy.conf:2

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"

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, 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

1

1 Answers

0
votes

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"

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.

There is no need for the 02_restart_nginx command, you can remove that one (as of Aug'19).

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.