【问题标题】:amazon aws elastic beanstalk. Custom Configuration Files not working亚马逊 AWS 弹性豆茎。自定义配置文件不起作用
【发布时间】:2014-05-16 03:17:15
【问题描述】:

我在使用 aws elastic beanstalk 中的自定义配置文件时遇到问题。

我的应用是 python flask app。

我将 01wsgi.config 文件放入 .ebextensions。

并压缩然后上传到弹性豆茎。

源部署好,但配置没有执行。

我怎样才能让它正常工作?

目录结构:

source_root
  - .ebextensions
     -- 01wsgi.config
  - application
  - application.wsgi

01wsgi.config 内容:

files:
  "/etc/httpd/conf.d/wsgi.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      LoadModule wsgi_module modules/mod_wsgi.so
      WSGIPythonHome /opt/python/run/baselinenv
      WSGISocketPrefix run/wsgi
      WSGIRestrictEmbedded On

      <VirtualHost *:80>
      #############
      # TYPES FIX #
      #############
      AddType text/css .css
      AddType text/javascript .js

      ####################
      # GZIP COMPRESSION #
      ####################
      SetOutputFilter DEFLATE
      AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml text/javascript application/x-javascript application/x-httpd-php
      BrowserMatch ^Mozilla/4 gzip-only-text/html
      BrowserMatch ^Mozilla/4\.0[678] no-gzip
      BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
      BrowserMatch \bMSI[E] !no-gzip !gzip-only-text/html
      SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip
      Header append Vary User-Agent env=!dont-vary

      Alias /static/(.*)? /opt/python/current/app/application/frontend/static-build/
      <Directory /opt/python/current/app/application/frontend/static-build/>
      Order allow,deny
      Allow from all
      Header append Cache-Control "max-age=2592000, must-revalidate"
      </Directory>

      WSGIScriptAlias / /opt/python/current/app/application.py

      <Directory /opt/python/current/app/>
      Order allow,deny
      Allow from all
      </Directory>

      WSGIDaemonProcess wsgi processes=1 threads=15 display-name=%{GROUP} \
      python-path=/opt/python/current/app:/opt/python/run/venv/lib/python2.7/site-packages user=wsgi group=wsgi \
      home=/opt/python/current/app
      WSGIProcessGroup wsgi
      WSGIScriptReloading On
      </VirtualHost>

我关注了以下文档:

http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers.html

已解决

将您的 wsgi.conf 文件放入 .ebextensions 目录。

并制作一个将 wsgi.conf 复制到 ondeck 的配置文件。

01wsgi.config 内容:

container_commands:
  replace_wsgi_config:
    command: "cp .ebextensions/wsgi.conf /opt/python/ondeck/wsgi.conf"

【问题讨论】:

  • 这对我不起作用。
  • 这是另一个展示如何使用 ebextensions 的示例。这是一个 PHP 示例,但如果你注意它只是一堆 shell 命令:stackoverflow.com/a/38880732/2130610

标签: amazon-web-services deployment configuration amazon-elastic-beanstalk


【解决方案1】:

我想添加一些关于另一个问题的信息:如果您进行不执行完整部署的更改(例如更改环境变量),Beanstalk 将覆盖您的 apache 主机文件。在大多数情况下,您的网络服务器将停止为您的应用提供服务,除非您实际上并未自定义 wsgi.conf

现在,要清楚,您是正确的,您需要将 WSGI 配置放在 .ebextentions 目录中。然后使用container command 将配置文件移动到EB 查看的位置。您可以使用以下命令安全地执行此操作:

# Replace the default wsgi with ours
cp .ebextensions/wsgi.conf ../wsgi.conf

为防止您的自定义 wsgi.conf 在不执行部署的更新期间被覆盖,您需要对重新创建 wsgi.conf 的本机 EB 挂钩进行猴子补丁。我没有找到任何与此相关的文档,但 custom hooks 已记录在案,并且本地文档以相同的方式工作。

这是我一直在使用的猴子补丁:

# Elastic Beanstalk always forces generation of apache hosts,
# stop it by returning true in the function that does it
sed '    /return True # DO NOT REGENERATE APACHE HOSTS/d' /opt/elasticbeanstalk/hooks/config.py \
  | sed -e 's/def generate_apache_config(params, filename):/def generate_apache_config(params, filename):\n    return True # DO NOT REGENERATE APACHE HOSTS/1' \
  -e 's/if not os.path.exists(WSGI_STAGING_CONFIG):/if not os.path.exists(WSGI_STAGING_CONFIG):\n        return True # DO NOT REGENERATE APACHE HOSTS/1' \
  > /tmp/config.py && mv -f /tmp/config.py /opt/elasticbeanstalk/hooks/config.py

通过 SSH 连接到 EB 实例并查看 /opt/elasticbeanstalk/hooks/config.py,您会看到 EB 在部署或更新环境期间做了什么。

祝你好运!

【讨论】:

  • 你把“猴子补丁”放在哪里?在你的wsgi.conf?您的自定义 wsgi.conf 文件是否与 requirements.txt 放在同一目录中?
  • @WayBehind 该补丁是删除/opt/elasticbeanstalk/hooks/config.py 中重新部署默认wsgi.conf 的行。可能有更好的方法可以做到这一点,已经很长时间了,我目前没有在 EB 上使用 Django。
猜你喜欢
  • 1970-01-01
  • 2023-04-10
  • 2015-12-28
  • 2021-12-12
  • 2018-12-22
  • 2015-04-03
  • 2018-03-30
  • 2017-07-03
  • 2016-10-17
相关资源
最近更新 更多