【问题标题】:AWS ElasticBeanstalk update without modifing Django wsgi.confAWS ElasticBeanstalk 更新而不修改 Django wsgi.conf
【发布时间】:2017-01-03 05:56:38
【问题描述】:

我在 AWS EB 中使用自动缩放部署了一个 django 应用程序。 这个应用程序使用带有令牌身份验证的 Django Rest。 为了使它工作,我必须在 etc/httpd/conf.d/wsgi.conf 文件中添加以下行:

RewriteEngine on
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

WSGIPassAuthorization On

问题是:当 AWS 进行自动缩放或 ElasticBeanstalk 环境升级时,wsgi.conf 文件会更新并删除自定义设置。

我怎样才能避免这种情况?

提前致谢

【问题讨论】:

    标签: python django apache amazon-web-services mod-wsgi


    【解决方案1】:

    为避免 ElasticBeanstalk 在自动缩放或重新初始化环境中的任何实例时擦除您的自定义设置,您应该使用您的 .ebextensions 脚本对您的 ec2 实例的 config 文件进行任何持久修改。

    (在您使用eb ssh“手动”测试这些修改之后)

    在这种情况下,您可以使用例如sed command 来编辑您的wsgi.conf 文件。

    将以下 container_command 添加到您的 yaml Elastic Beanstalk 配置文件中(即:.ebextension/yourapp.config):

    03_wsgipass: command: 'sed -i -f .ebextensions/wsgi_update.sed ../wsgi.conf'

    它应该看起来像这样:

    container_commands:
      01_migrate:
        command: "django-admin.py migrate --noinput"
        leader_only: true
      02_collectstatic:
        command: "django-admin.py collectstatic --noinput"
      03_wsgipass:
        command: 'sed -i -f .ebextensions/wsgi_update.sed ../wsgi.conf'
    

    .ebextensions文件夹的wsgi_update.sed中创建一个新文件,内容如下:

    /<Virtual/ a\
    RewriteEngine On\
    RewriteCond %{HTTP:Authorization} ^(.*)\
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
    
    /<\/Virtual/ a\
    WSGIPassAuthorization On
    

    这是一个小的sed program 例如,它将在您的&lt;VirtualHost&gt; 块中添加apache mod_rewrite 规则,并在您的wsgi.conf 文件中的结束标记&lt;/VirtualHost&gt; 之后添加WSGIPassAuthorization

    它将在每个应用程序部署到您的环境中通过自动缩放创建的任何现有或新实例时执行。

    查看Using the AWS Elastic Beanstalk Python Platform了解更多信息

    【讨论】:

      猜你喜欢
      • 2016-10-25
      • 2013-03-03
      • 2017-08-02
      • 1970-01-01
      • 2015-01-18
      • 2019-11-03
      • 2021-10-16
      • 2021-11-17
      • 2018-04-14
      相关资源
      最近更新 更多