I am switching from the Django development server to Apache for production. To this end, I installed modwsgi and specified the following in apache2.conf.
# Run my django application.
WSGIScriptAlias / /home/david/registration/registration/wsgi.py
WSGIPythonPath /home/david/registration
<Directory /home/david/registration/registration>
<Files wsgi.py>
Order deny,allow
Allow from all
</Files>
</Directory>
When I restart Apache, I find that my application loads in my browser, but none of the CSS or images do.
Previously, I had been using staticfiles to manage my static files. I had these settings.
# Absolute path to the directory static files should be collected to.
# Don't put anything in this directory yourself; store your static files
# in apps' "static/" subdirectories and in STATICFILES_DIRS.
# Example: "/home/media/media.lawrence.com/static/"
STATIC_ROOT = '/home/david/static/'
# URL prefix for static files.
# Example: "http://media.lawrence.com/static/"
STATIC_URL = '/static/'
The static files used to working, but not any more. Why does switching to Apache prevent my static files from loading?
The best option for work with apache2 and wsgi and django is use a new file in /etc/apache2/sites-enabled/mynewsite.apache (the extension doesn´t matter)
The file must look like this:
You need to tell apache to serve your django application but also you need tell it that Apache serves the files.