Customizing Nginx Configuration in AWS Elastic Beanstalk

感情迁移 提交于 2019-12-02 22:16:21

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

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"

I might be a little late with the response here, but I've discovered another, less intrusive way to configure nginx on Elastic Beanstalk. You can specify configuration files for nginx directly by creating an .ebextensions/nginx/conf.d directory. Any config files found inside are automatically copied to your /etc/nginx/conf.d/ directory during the EB deployment. This seems to be a more robust solution.

Documentation available here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/java-se-nginx.html

EDIT: As pointed out in comments, Elastic Beanstalk has inconsistent implementations between platforms. The documentation here is for Java SE, and it appears this documentation is not relevant for all platforms.

Israel Barba

this is my configuration and worked for me. You have to include it inside of the http block.

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

I got it working like this. No need to restart or reload nginx since the commands (and not container_commands) runes BEFORE the application deploy.

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"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!