Amazon Elastic Beanstalk not serving django static files

Amazon Elastic Beanstalk not serving django static files

elastic beanstalk python
django static files not working
django collectstatic
aws deploy django elastic beanstalk
django static files not found
django elastic beanstalk aws

I am trying to put up a simple django app on elastic beanstalk. I thought I had the static parts of the app figured out as it works with heroku and on a server that was set up manually. In debugging I even checked in a pushed the static files in the static directory to try to simplify things. The mapping seems very strange in that it doesn't seem to follow the STATIC_ROOT.

My relevant configs:

PROJECT_ROOT = os.path.abspath(os.path.dirname(__name__))
STATIC_ROOT = os.path.join(PROJECT_ROOT,'static/')
STATIC_URL = '/static/'
#    'django.contrib.staticfiles.finders.DefaultStorageFinder',

(r'^static/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_ROOT}),


[Wed Dec 26 15:39:04 2012] [error] [client] File does not exist: /opt/python/current/app/css, referer - - 
[26/Dec/2012:15:39:04 +0000] "GET /static/css/styles.css HTTP/1.1" 404 329 "http://" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.101 Safari/537.11"

Have you found the solution yet? just to let you know. I came across the same problem today, and I realized that I forgot this option in the .ebextensions/.config file. make sure you have it too

  - namespace: aws:elasticbeanstalk:container:python:staticfiles
    option_name: /static/
    value: static/

Serving static files - AWS Elastic Beanstalk, Use AWS Elastic Beanstalk configuration options to configure your environment's proxy server to serve static content from a folder in your source code. I have set up a deploy through Elastic Beanstalk for a simple Django app. The site seems to be working, but the static files are not being served correctly (styles and scripts are missing).

To support multiple apps and do this you need to run collectstatic

STATIC_ROOT = os.path.join(BASE_DIR, "static")

Make sure you have a folder called "static" in your root

In your ebs config file eg. (02_python.config or similar)

        /static/: "static/"

Then before you upload to ebs run python collectstatic

This collects all the static files in one folder which you have already pointed to in your config.

Then you can run eb deploy like normal

Opptionally if you don't want to commit the static files to your source control twice and want the server to do this for you add this to your config

    command: "source /opt/python/run/venv/bin/activate && python collectstatic --noinput"

So your file should look something like this:

  command: "source /opt/python/run/venv/bin/activate && python collectstatic --noinput"

      WSGIPath: app/
      /static/: "static/"

This will run collect static for you when you run eb deploy

Static Files not being served using, Static Files not being served using Django. Posted by: I have removed all static file configuration from .elasticbeanstalk/optionsettings I don't have a direct answer to your question, other than to ask you why are you trying to do it this way. The best practice is to move your static files to S3 or ideally, CloudFront (or another non-AWS solution).

For me, the problem was having

STATIC_ROOT = os.path.join(os.path.dirname(__file__), 'static')

Instead, I changed it to

STATIC_ROOT = 'static'

Also, my .conf file has

    "/static/": "static/"

Deploying a Django App to AWS Elastic Beanstalk – Real Python, Let's look at how to deploy a Django App to AWS Elastic Beanstalk. Static Files; Using S3 for Media Storage; Apache Config; Troubleshooting; Conclusion (​This is probably not a great choice for security reasons, though.) Name) · Add bucket permissions · Configure your Django app to use S3 to serve your static files. For details about configuring static files using the Elastic Beanstalk console, see Serving static files. By default, the proxy server in a Python environment serves any files in a folder named static at the /static path.

I did the following to fix static path in beanstalk

STATIC_URL = '/static/'

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
STATIC_ROOT = os.path.join(BASE_DIR, 'static')

    "/static/": "static/"

Deploying a Django application to Elastic Beanstalk, file named django.config with the following text. Example ~/ebdjango/.​ebextensions/django.config. option_settings: aws:elasticbeanstalk:container:​python:  Using Amazon S3 to Store your Django Site's Static and Media Files Storing your Django site's static and media files on Amazon S3, instead of serving them yourself, can improve site performance. It frees your servers from handling static files themselves, lets you scale your servers easier by keeping media files in a common place, and is a

All previous answers didn't help me This works for me.

Basically I created two steps inside .ebextensions


        command: "source /opt/python/current/env && source /opt/python/run/venv/bin/activate && cd /opt/python/current/app && python migrate --noinput"
        leader_only: true
        command: "source /opt/python/current/env && source /opt/python/run/venv/bin/activate && cd /opt/python/current/app && python touch_superuser"
        leader_only: true
        WSGIPath: config/
        NumProcesses: 2
        NumThreads: 10
        STAGING: 1
        DJANGO_SETTINGS_MODULE: config.settings.production
        "/static/": "htdocs/static/"
        "/media/": "htdocs/media/"

config/ Could be a different path in your project


    mode: "000755"
    owner: root
    group: root
    content: |
      set -xe

      source /opt/python/current/env
      source /opt/python/run/venv/bin/activate
      cd /opt/python/current/app && python collectstatic --noinput

      echo "Statics collected...!!"

An important thing, you settings/*.py should match with your static path that EBS serves, in my case this is my config.

PROJECT_PATH = dirname(dirname(dirname(__file__)))
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'htdocs/media')
STATIC_ROOT = os.path.join(PROJECT_PATH, 'htdocs/static')

Using the Elastic Beanstalk Python platform, The AWS Elastic Beanstalk Python platform is a set of platform versions for Python application source that contain static files to paths served by the proxy server. For details about configuring static files using the Elastic Beanstalk console, a property named DJANGO_SETTINGS_MODULE to configure Django to use a  The Elastic Beanstalk Java SE platform includes an nginx server that acts as a reverse proxy, serving cached static content and passing requests to your application. The platform provides configuration options to configure the proxy server to serve static assets from a folder in your source code to reduce the load on your application.

Deploying Django Project to AWS Elastic Beanstalk, At the same time, use of Elastic Beanstalk does not deprive you from Creating .​ebextensions directory and django.config file images, we need to configure a static files storage via STATIC_ROOT setting in file. Configure your Django application for Elastic Beanstalk. Now that you have a Django-powered site on your local machine, you can configure it for deployment with Elastic Beanstalk. By default, Elastic Beanstalk looks for a file named to start your application. Because this doesn't exist in the Django project that you've created

Blog - Deploying your Django static files to AWS (Part 4), Deploying your Django static files to AWS (Part 4) and host them on the AWS Elastic File System, using Whitenoise to serve them to CloudFront. So how does the load balancer know whether or not an instance is healthy? Configuración de la aplicación de Django para Elastic Beanstalk. Ahora que ya tiene un sitio de Django en su equipo local, puede configurarlo para implementarlo con Elastic Beanstalk. De forma predeterminada, Elastic Beanstalk busca un archivo llamado para iniciar su aplicación. Como este archivo no existe en el proyecto de

Elastic Beanstalk - Daphne is not serving static files : django, django does not serve static files when DEBUG=False. That guide is assuming you're using Amazon's S3 services which basically means there  To do this we need to create migration python migrate and superuser via python createsuperuser command, add option STATIC_ROOT = 'static' to the django settings and collect static files via python collectstatic