Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Customizing Nginx Configuration in AWS Elastic Beanstalk

I'm running a rails application on Ruby 2.0/Puma instances and am trying to customize the nginx configuration. I need to increase the permitted request size to allow file uploads. I've found some other posts that have lead me to add this to my .ebextensions:

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

That does create the file as expected, but it doesn't seem to work until I manually restart nginx. Because of that, I've tried to figure out a way to restart nginx with .ebextensions commands, but haven't had any success. Does anyone know of a way to restart nginx with .ebextensions or know of a better approach to solving this problem?

like image 572
Graham Avatar asked Jan 28 '15 21:01

Graham


People also ask

Where is nginx config Elastic Beanstalk?

conf is the filename which will be created on the Elastic Beanstalk EC2 instances. By default this configuration is in the file /etc/nginx/conf.

Does Elastic Beanstalk use nginx?

Elastic Beanstalk uses nginx as the reverse proxy to map your application to your Elastic Load Balancing load balancer on port 80. Elastic Beanstalk provides a default nginx configuration that you can either extend or override completely with your own configuration.

How do I change the port on my Elastic Beanstalk?

By default, Elastic Beanstalk configures the proxy to forward requests to your application on port 5000. You can override the default port by setting the PORT environment property to the port that your main application listens on.


2 Answers

I found a way to restart nginx after deployment using an undocumented technique for running post-deployment scripts. 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
like image 170
Graham Avatar answered Oct 16 '22 20:10

Graham


To reload the nginx config, 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 are run after the application and web server have been set up and the application has been extracted, but before the application is deployed. container_commands are processed in lexicographical order by name.

container_commands:
  01_reload_nginx:
    command: "service nginx reload"
like image 43
Ari Avatar answered Oct 16 '22 18:10

Ari