[Django]-Static files not being served on AWS Lightsail

2👍

You need to add Alias /static/ /opt/bitnami/apps/django/django_projects/Project/static/ to your virtualhost config so the server knows to map /static/ requests to that folder.

👤Victor

1👍

I wasted A LOT of time on this, here’s my final working bitnami.conf file.

<VirtualHost _default_:80>
    WSGIDaemonProcess django_site python-home=/opt/bitnami/projects/env python-path=/opt/bitnami/projects/django_site.com
    WSGIProcessGroup django_site
    WSGIScriptAlias / /opt/bitnami/projects/django_site.com/django_site/wsgi.py

    <Directory /opt/bitnami/projects/django_site.com>
        AllowOverride all
        Require all granted
        Options FollowSymlinks

        WSGIProcessGroup django_site
    </Directory>

    Alias /static/ /opt/bitnami/projects/django_site.com/static/
</VirtualHost>

Include "/opt/bitnami/apache/conf/bitnami/bitnami-ssl.conf"

Note:

  • I know it’s not recommended, but I put all the codes inside bitnami.conf and neglected httpd-app.conf and httpd-prefix.conf

  • I created python virtualenv at /opt/bitnami/projects/env and installed all needed libraries there

  • I added the below code to my settings.py file before running python manage.py collectstatic

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'

Leave a comment