[英]Unable to serve Django static files on AWS elastic-beanstalk
我搜索了很多問題和答案,AWS 和 Django(2.0) 文檔,但仍然無法提供靜態文件。 我是 AWS 的新手,只制作了基本的 Web 應用程序。
我的 settings.py 有:
INSTALLED_APPS = [
..
'django.contrib.staticfiles',
..
]
STATIC_ROOT = os.path.join(BASE_DIR,"static")
STATIC_URL = '/static/'
我的項目目錄:
|.ebextensions
|--django.config
|.elasticbeanstalk
|--config.yml
|app
|--migrations
|--static
|--tempates
|--admin.py
|--......
|--views.py
|project
|--settings.py
|--urls.py
|--wsgi.py
|static
|manage.py
|requirements
我的 django.config 有:
container_commands:
01_collectstatic:
command: "source /opt/python/run/venv/bin/activate && python manage.py collectstatic --noinput"
option_settings:
"aws:elasticbeanstalk:container:python":
WSGIPath: awtest/wsgi.py
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
HTML 源代碼:
<html>
<head
<title>Home</title>
</head>
<body>
<img src="/static/app/symbol-logo.png" alt="" style="width:50px;height:60px;"">
<h1>AWS</h1>
</body>
</html>
當我在我的計算機上運行它時,它工作正常,我可以看到圖像,但是一旦我在 AWS beanstalk 上部署,我就無法看到圖像,當我檢查源並單擊圖像 url 時,它說Forbidden, you don't have permission to access the image on server
。
誰能指出我可能出錯的地方? 任何幫助將不勝感激!
我使用不同的配置在 AWS 的不同實例中部署了它,並且它有效。
從 django.config 我刪除了
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"
在 settings.py 文件中我做了STATIC_ROOT = 'static'
在 Elastic-beanstalk 控制台的配置設置中我改變了
/static/ = /static/
到
/static/ = static/
在最新版本的 EBS 中,命名空間更改為aws:elasticbeanstalk:environment:proxy:staticfiles
,如下所示:
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.