Reputation: 2780
I currently have an multi-docker container application (nginx, postgres RDS, Django) running on Elastic BeanStalk and I am able to use it but the static files (CSS files and JS scripts) are not loaded. This is my current configuration:
nginx setup file
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 (folder)
django.config (file)
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/'
If I remove the folder .ebextensions
folder and load the app, it will work without displaying the static files but if I add the folder with the django.conf
file the app won't deploy and I will encounter the error: Invalid option specification (Namespace: 'aws:elasticbeanstalk:container:python:staticfiles', OptionName: '/static/'): Unknown configuration setting.
In one post I found (Serving static files in Django) it is mentioned that all staticfiles directives from .config files should be removed and under the Software Configuration I should configure the static files under the Static File section, however, this Static File section is not even displayed. What code am I missing for displaying the static files? Thanks in advance for your suggestions and answers.
Upvotes: 2
Views: 2010
Reputation: 416
There is new settings for 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
Upvotes: 7