skip to Main Content

Static files are not loading in production of my Django project. I am using mod-wsgi to serve the static files.

Static files were serving fine in development (when DEBUG=True), but now I get 404 errors when the static files are trying to be called.

My file structure is:
https://imgur.com/a/FuFZSSh

/etc/apache2/sites-available/mysite.conf

<VirtualHost *:80>
    ServerName <ip address>
    ErrorLog ${APACHE_LOG_DIR}/mysite-error.log
    CustomLog ${APACHE_LOG_DIR}/mysite-access.log combined

    WSGIDaemonProcess mysite processes=2 threads=25 python-path=/var/www/mysite
    WSGIProcessGroup mysite
    WSGIScriptAlias / /var/www/mysite/mysite/wsgi.py

    Alias /robots.txt /var/www/mysite/static/robots.txt
    Alias /favicon.ico /var/www/mysite/static/favicon.ico
    Alias /static/ /var/www/mysite/static/
    Alias /media/ /var/www/mysite/media/

    <Directory /var/www/mysite/mysite>
        <Files wsgi.py>
            Require all granted
        </Files>
    </Directory>

    <Directory /var/www/mysite/static>
        Require all granted
    </Directory>

    <Directory /var/www/mysite/media>
        Require all granted
    </Directory>
</VirtualHost>

settings.py

STATIC_ROOT = '/var/www/mysite/static_root/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, "static"),
)
STATIC_URL = '/static/'

MEDIA_ROOT = '/var/www/mysite/media/'
MEDIA_URL = '/media/'

Any help would be greatly appreciated 🙂

2

Answers


  1. Apache should be looking at your STATIC_ROOT directory, after you’ve run collectstatic.

    <Directory /var/www/mysite/static_root>
        Require all granted
    </Directory>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search