[英]Static files not loading on Amazon Bean Stalk for Django app
我知道這個問題已經被問過很多次了,我已經嘗試過 Stackoverflow 上提到的所有解決方案,但我沒有讓我的工作。 所以這是我的問題:
我的代碼(在 eb 上)位於:
/var/app/current
我的文件夾結構如下:
.ebextensions
platform
platform_site
manage.py
settings.py
我的 dbmigrate.config 文件(under.ebextensions)包含以下條目:
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
container_commands:
03_collect_static:
command: "source /var/app/venv/*/bin/activate && python3 manage.py collectstatic"
leader_only: true
static 文件在運行時未加載。 因此,當我查看日志文件時,日志文件 (/var/log/cfn-init-cmd.log) 顯示 static 文件已復制到此文件夾:
[INFO] 398 static files copied to '/var/app/staging/platform-site/settings/static'
但是,當我查看 NGNIX 的日志(/var/log/nginx/error.log)時,我看到它正在嘗試從另一個文件夾加載 static 文件:
[error] 1717#1717: *11 open() "/var/app/current/static/platform/images/sensitive_data.png" failed
(2: No such file or directory), client: 172.31.26.84, server: , request: "GET /static/platform/images/sensitive_data.png HTTP/1.1", host: "xxxx.elasticbeanstalk.com
這很奇怪。 為什么要復制到“暫存”文件夾並嘗試從“當前”文件夾中讀取? 我不知道為什么會這樣。
有趣的是,我試圖在我的 EB 安裝中搜索這個文件夾,但它不存在
var/app/staging/platform-site
你能幫忙嗎?
我的設置文件有以下條目:
STATIC_ROOT = os.path.join(PROJECT_ROOT, "static/")
這是錯誤的。 我將其更改為以下內容並且有效。
STATIC_ROOT = '靜態'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.