2 回答

TA贡献1943条经验 获得超7个赞
为了实现这一点,我必须在包含以下内容的 .ebextensions 文件夹中创建一个配置。
您需要从您的服务器复制 wsgi.conf 文件,以确保您首先拥有正确的 EB 设置。
files:
"/opt/elasticbeanstalk/local/override_wsgi_conf.py":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env python
import os
import sys
sys.path.append(os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))
import config
MY_APACHE_TEMPLATE = r'''
# Customized wsgi.conf. If you're seeing this, good!
LoadModule wsgi_module modules/mod_wsgi.so
WSGIPythonHome /opt/python/run/baselinenv
WSGISocketPrefix run/wsgi
WSGIRestrictEmbedded On
<VirtualHost *:80>
Alias /static/ /opt/python/current/app/static/
<Directory /opt/python/current/app/static/>
Order allow,deny
Allow from all
</Directory>
WSGIScriptAlias / /opt/python/current/app/key_collector_backend/wsgi.py
<Directory /opt/python/current/app/>
Require all granted
</Directory>
WSGIDaemonProcess wsgi processes=3 threads=20 maximum-requests=10000 display-name=%{GROUP} \
python-home=/opt/python/run/venv/ \
python-path=/opt/python/current/app user=wsgi group=wsgi \
home=/opt/python/current/app
WSGIProcessGroup wsgi
</VirtualHost>
LogFormat "%h (%{X-Forwarded-For}i) %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
WSGIPassAuthorization On
WSGIApplicationGroup %{GLOBAL}
'''
def main():
try:
WSGI_STAGING_CONFIG = config.get_container_config('wsgi_staging_config')
print 'Overriding WSGI configuration in %s' % WSGI_STAGING_CONFIG
open(WSGI_STAGING_CONFIG, 'w').write(MY_APACHE_TEMPLATE)
except Exception, e:
config.emit_error_event(config.USER_ERROR_MESSAGES['badappconfig'])
config.diagnostic("Error generating config during configdeploy/pre: %s"
% str(e))
sys.exit(1)
if __name__ == '__main__':
config.configure_stdout_logger()
main()
commands:
5_app_deploy_dir:
command: "mkdir -p /opt/elasticbeanstalk/hooks/appdeploy/pre"
5_config_deploy_dir:
command: "mkdir -p /opt/elasticbeanstalk/hooks/configdeploy/pre"
10_app_deploy_file:
command: "cp -p /opt/elasticbeanstalk/local/override_wsgi_conf.py /opt/elasticbeanstalk/hooks/appdeploy/pre/90_override_wsgi_conf.py"
20_config_deploy_file:
command: "cp -p /opt/elasticbeanstalk/local/override_wsgi_conf.py /opt/elasticbeanstalk/hooks/configdeploy/pre/90_override_wsgi_conf.py"

TA贡献1876条经验 获得超5个赞
您必须替换使用 WSGIDaemonProcess 指令的 Apache 服务器配置。
通过 SSH 连接到运行您的弹性 beanstalk 应用程序的 EC2 实例并切换到配置目录/etc/httpd/conf.d/。
在那里寻找包含WSGIDaemonProcess.
grep -rnwl . -e 'WSGIDaemonProcess'
替换 elasticbeanstalk 应用程序配置中匹配文件的内容。
生成配置的位置(在应用程序部署的暂存阶段)可以使用 shell 命令方便地获取:
/opt/elasticbeanstalk/bin/get-config container -k wsgi_staging_config
.ebextensions/wsgi.config
files:
/opt/elasticbeanstalk/hooks/appdeploy/pre/05_wsgi.sh:
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
# Set max-requests option in generated wsgi.conf
sed -i -e '/WSGIDaemonProcess wsgi/ a\
\ \ maximum-requests=1000 \\
' $(/opt/elasticbeanstalk/bin/get-config container -k wsgi_staging_config)
添加回答
举报