Configuring Nginx Configuration in AWS Elastic Beanstalk

I am running the rails application on Ruby 2.0 / Puma instances and trying to configure the nginx configuration. I need to increase the allowed request size to allow file downloads. I found several other posts that made me add this to my .ebextensions:

files: "/etc/nginx/conf.d/proxy.conf" : mode: "000755" owner: root group: root content: | client_max_body_size 70M; 

This creates the file as expected, but it doesn't seem to work until I manually restart nginx. Because of this, I tried to figure out a way to restart nginx with the .ebextensions commands, but had no success. Does anyone know how to restart nginx using .ebextensions or find out the best approach to solve this problem?

+7
ruby-on-rails amazon-web-services elastic-beanstalk nginx amazon-elastic-beanstalk
source share
4 answers

I found a way to reload nginx after deployment using an undocumented method to run scripts after deployment. I added this to my .ebextensions:

 files: "/opt/elasticbeanstalk/hooks/appdeploy/post/03_restart_nginx.sh": mode: "000755" owner: root group: root content: | #!/usr/bin/env bash service nginx restart 
+8
source share

To reload nginx configuration you can use container_commands

From http://www.infoq.com/news/2012/11/elastic-beanstalk-config-files :

The container_commands key allows you to execute commands for your container. They start after the application and the web server have been configured and the application has been extracted, but before the application is deployed. container_commands are processed in lexicographic order by name.

 container_commands: 01_reload_nginx: command: "service nginx reload" 
+4
source share

this is my configuration and worked for me. You must include it in the http block.

 files: "/etc/nginx/conf.d/proxy.conf" : mode: "000755" owner: root group: root content: | http { client_max_body_size 20M; } 
+1
source share

I worked like that. There is no need to restart or reboot nginx since the commands lines (and not container_commands ) are before deploying the application.

 commands: 01-get-nginx-conf-file: command: "aws s3 cp s3://somepath/nginx.conf /home/ec2-user" 02-replace-default-nginx-config: command: "cp /home/ec2-user/nginx.conf /etc/nginx/nginx.conf" 
0
source share

All Articles