I’ve followed this tutorial to deploy my django project : https://www.digitalocean.com/community/tutorials/how-to-serve-django-applications-with-apache-and-mod_wsgi-on-debian-8
Why the static files can’t be loaded from apache?
I am using Debian9, Python3.5 and Django 1.11
This is my virtual host configuration:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Alias /static /home/alex/djangoproject/static
<Directory /home/alex/djangoproject/static>
Require all granted
</Directory>
<Directory /home/alex/djangoproject/cpanel>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
WSGIDaemonProcess djangoproject python-home=/home/alex/djangoproject/djangoprojectenv python-path=/home/alex/djangoproject
WSGIProcessGroup djangoproject
WSGIScriptAlias / /home/alex/djangoproject/cpanel/wsgi.py
</VirtualHost>
`
And the apache error from error.log:
AH01630: client denied by server configuration /home/alex/djangoproject/static
And my settings.py config related to static foder
STATIC_URL = '/static/'
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')
2
Answers
Solved this by adding the django project name directory before static so this :
Will become this:
Performed ./migrate.py collectstatic , restart apache and all running smoothly.
For Ubuntu 20 :
in
/etc/apache2/apache2.conf
add after line 175:
in
/etc/apache2/sites-available/000-default.conf
, use this quick setup:Restart apache :