阅读背景:

在AWS Elastic Beanstalk中自定义Nginx配置

来源:互联网 

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:

我正在Ruby 2.0 / Puma实例上运行rails应用程序,我正在尝试自定义nginx配置。我需要增加允许的请求大小以允许文件上传。我发现了其他一些帖子让我把它添加到我的.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?

这确实按预期创建了文件,但在我手动重启nginx之前它似乎不起作用。因此,我试图找出一种使用.ebextensions命令重启nginx的方法,但没有取得任何成功。有没有人知道用.ebextensions重新启动nginx的方法,或者知道更好的方法来解决这个问题?

5 个解决方案

#1


10  

I found a way to restart nginx after deployment using an undocumented technique for running post-deployment scripts. I added this to my .ebextensions:

我找到了一种在部署后使用未记录的技术重新启动nginx以运行部署后脚本的方法。我把它添加到我的.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

#2


4  

To reload the nginx config, you can use container_commands

要重新加载nginx配置,可以使用container_commands

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

来自https://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键允许您为容器执行命令。它们在应用程序和Web服务器已设置并且应用程序已解压缩但在部署应用程序之前运行。 container_commands按名称按字典顺序处理。

container_commands:
  01_reload_nginx:
    command: "service nginx reload"

#3


2  

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.

我可能会对这里的响应有点迟,但我发现了另一种不那么具有侵入性的方法来在Elastic Beanstalk上配置nginx。您可以通过创建.ebextensions / nginx / conf.d目录直接为nginx指定配置文件。在EB部署期间,内部找到的任何配置文件都会自动复制到/etc/nginx/conf.d/目录中。这似乎是一个更强大的解决方案。

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

此处提供的文档: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.

编辑:正如评论中指出的,Elastic Beanstalk在平台之间具有不一致的实现。此处的文档适用于Java SE,看来此文档与所有平台无关。

#4


1  

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

这是我的配置并为我工作。您必须将其包含在http块中。

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

#5


0  

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.

我让它像这样工作。无需重新启动或重新加载nginx,因为在应用程序部署之前命令(而不是container_commands)符文。

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"

分享到: