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 命令方便地獲?。?/p>
/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)
添加回答
舉報