[英]I can't figure out how to serve Static Files using AWS Elasticbeanstalk
我正在使用在 Elastic Beanstalk 的 64 位 Amazon Linux/2.7.7 上運行的 Python 3.6。
這是我的文件結構:
- analytics
-- (a bunch of files that I think are irrelevant here)
- db.sqlite3
- ecs_site
-- __init__.py
-- __pycache__
-- settings.py
-- static
-- css
-- (a bunch of files - important)
-- fonts
-- (a bunch of files - important)
-- images
-- (a bunch of files - important)
-- templates
-- (a bunch of files that I think are irrelevant here)
-- urls.py
-- wsgi.py
- manage.py
- pages
-- (a bunch of files that I think are irrelevant here)
- requirements.txt
在 settings.py 文件中是這樣的:
#STATIC_ROOT = os.path.dirname(__file__)
STATIC_ROOT = os.path.join(BASE_DIR, "ecs_site", "static")
#SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
#STATICFILES_DIRS = [os.path.join(SITE_ROOT, 'static/')]
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'static')]
STATIC_URL = '/static/'
#STATICFILES_DIRS = [os.path.join(BASE_DIR, 'ecs_site/static/'), os.path.join(BASE_DIR, 'ecs_site/static/images/'),
#os.path.join(BASE_DIR, 'ecs_site/static/fonts/'), os.path.join(BASE_DIR, 'ecs_site/static'), os.path.join(BASE_DIR, 'ecs_site/static/images'),
#os.path.join(BASE_DIR, 'ecs_site/static/fonts')]
#STATICFILES_DIRS = [os.path.join(BASE_DIR, '/static/'), os.path.join(BASE_DIR, '/static/images/'),
#os.path.join(BASE_DIR, '/static/fonts/'), os.path.join(BASE_DIR, '/static'), os.path.join(BASE_DIR, '/static/images'),
#os.path.join(BASE_DIR, '/static/fonts')]
在配置文件中,這是我所擁有的(在 AWS EB 控制台中設置):
解決此問題的方法是查看ecs_site
目錄。 如果您運行命令ls -lhra
,它將顯示一個名為.ebextensions
文件夾的隱藏目錄。 如果該文件夾不存在,則在該文件夾中創建一個名為django.config
的文件。 在該文件中,我包含以下代碼:
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTING_MODULE: "ecs_site.settings"
PYTHONPATH: "/opt/python/current/app/ecs_site:$PYTHONPATH"
"aws:elasticbeanstalk:container:python":
WSGIPath: "ecs_site/ecs_site/wsgi.py"
這解決了問題。 我不知道確切原因,但它奏效了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.