我目前在Elastic BeanStalk上运行着一个多码头集装箱应用程序(nginx,postgres RDS,Django),虽然可以使用它,但未加载静态文件(CSS文件和JS脚本)。这是我当前的配置:
nginx设置文件
user nginx;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
client_max_body_size 100M;
server {
listen 80;
charset utf-8;
server_name mydashboard.com;
access_log /dev/stdout;
error_log /dev/stdout info;
location /media/ {
alias /var/www/media/;
}
location /static/ {
alias /var/www/static/;
}
location / {
proxy_pass http://web:8888;
proxy_set_header host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $server_name;
}
}
}
.ebextensions(文件夹)
django.config(文件)
option_settings:
"aws:elasticbeanstalk:application:environment":
DJANGO_SETTINGS_MODULE: "mydashboard.settings"
"ALLOWED_HOSTS": ".elasticbeanstalk.com"
"aws:elasticbeanstalk:container:python":
WSGIPath: mydashboard/mydashboard/wsgi.py
"aws:elasticbeanstalk:container:python:staticfiles":
"/static/": "www/static/"
settings.py
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(BASE_DIR,'static'),)
STATIC_ROOT = os.path.join(BASE_DIR, "..", "www", "static")
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
MEDIA_URL = '/media/'
如果我删除文件夹.ebextensions
并加载应用程序,它将在不显示静态文件的情况下工作,但是如果我将文件夹与django.conf
文件一起添加,则该应用程序将不会部署,并且我会遇到错误:Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/static/'): Unknown configuration setting.
在我发现(Serving static files in Django)的一篇文章中,提到应该删除.config文件中的所有staticfiles指令,并且在“软件配置”下,我应该在“静态文件”部分下配置静态文件,但是,文件部分甚至不显示。显示静态文件时我缺少什么代码?在此先感谢您的建议和解答。
答案 0 :(得分:3)
EBS有新设置
option_settings:
aws:elasticbeanstalk:container:python:
WSGIPath: mysite.wsgi:application
aws:elasticbeanstalk:environment:proxy:staticfiles:
/static: static
container_commands:
01_collectstatic:
command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py collectstatic --noinput"
02_migrate:
command: "source /var/app/venv/staging-LQM1lest/bin/activate && python manage.py migrate --noinput"
leader_only: true