[英]How do I configure aws:elasticbeanstalk:container:python:staticfiles in Elastic Beanstalk?
我正在嘗試運行eb create
以將我的 Django 項目部署到 AWS。 我得到的錯誤是ERROR: ServiceError - Configuration validation exception: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/static/'): Unknown configuration setting.
我不確定這個錯誤是什么意思,而且我找不到太多關於它的東西。
我試圖在.ebextensions/django.config
中定義這個變量。
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: ebdjango.wsgi:application
aws:elasticbeanstalk:container:python:staticfiles:
/static/: 'frontend/views/build/static/'
我的 settings.py 配置了以下變量:
STATIC_URL = '/static/'
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'frontend/views/build/static')
]
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
我正在嘗試在 Amazon Linux 2 上運行此 ebs 實例
如果您的環境使用基於 Amazon Linux 2 的平台分支,請使用 aws:elasticbeanstalk:environment:proxy:staticfiles 命名空間。
以下示例配置文件告訴代理服務器提供文件:
Example.ebextensions/django.config
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static/: static
筆記:
STATIC_ROOT
路徑而不是STATICFILES_DIRS
啊,是的,Amazon Linux 2 文檔並未完全跟上速度。
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: /path/to/static
創建一個名為.platform/hooks/01_collect_static.sh的部署后掛鈎文件,並使用 chmod 使其可執行。
輸入以下內容:
#!/bin/bash
source "$PYTHONPATH/activate" && {
python manage.py collectstatic --noinput;
}
在部署時,django 現在會將您的 static 文件收集到您在settings.py中定義的文件夾中。
注意,我在這里也包含了我的 migrate 命令,這樣我的鈎子文件看起來像:
#!/bin/bash
source "$PYTHONPATH/activate" && {
if [[ $EB_IS_COMMAND_LEADER == "true" ]];
then
# log which migrations have already been applied
python manage.py showmigrations;
# migrate
python manage.py migrate --noinput;
else
echo "this instance is NOT the leader";
fi
python manage.py collectstatic --noinput;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.