我搜索了很多问题和答案,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。
有谁能指出我可能出错的地方吗?任何帮助都将不胜感激!
发布于 2018-03-04 17:19:07
我用不同的配置在AWS的不同实例中部署了它,它起作用了。
从django.config中删除
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "static/"在settings.py文件中,我创建了STATIC_ROOT = 'static'
在Elastic-beanstalk控制台的配置设置中,我更改了
/static/ = /static/至
/static/ = static/ 发布于 2020-06-17 16:11:52
在EBS的最新版本中,名称空间更改为aws:elasticbeanstalk:environment:proxy:staticfiles,如下所示:
option_settings:
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: statichttps://stackoverflow.com/questions/49050108
复制相似问题