亚马逊aws弹性豆茎.自定义配置文件不起作用

dor*_*yle 11 deployment configuration amazon-web-services amazon-elastic-beanstalk

我在aws弹性beanstalk中遇到自定义配置文件的问题.

我的应用程序是python flask应用程序.

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

并将其压缩然后上传到弹性豆茎.

源部署得很好,但配置没有执行.

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

目录结构:

source_root
  - .ebextensions
     -- 01wsgi.config
  - application
  - application.wsgi
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

我按照下面的文件:

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"
Run Code Online (Sandbox Code Playgroud)

Rya*_*her 2

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

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

# Replace the default wsgi with ours
cp .ebextensions/wsgi.conf ../wsgi.conf
Run Code Online (Sandbox Code Playgroud)

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

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

# 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
Run Code Online (Sandbox Code Playgroud)

通过 SSH 连接到 EB 实例并进行查看/opt/elasticbeanstalk/hooks/config.py,您将看到 EB 在环境部署或更新期间执行的操作。

快乐AWS!