我搜索了许多问题和答案,AWS和Django(2.0)文档,但仍然无法提供静态文件。我是AWS新手,只做了基本的网络应用程序。
我的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上部署时,我无法看到图像,当我检查源并点击图像网址时,它说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/