Reputation: 399
What directory must the DocumentRoot in Apache be set to run a Django app is it the static directory but that does not work? Thanks to all for the help in advance.
Upvotes: 5
Views: 4747
Reputation: 535
When using Django, the DocumentRoot
directive is not needed.
Under the traditional approach to web sites, where Apache serves pre-written HTML files, Apache uses DocumentRoot
, say
DocumentRoot = /var/www/website
so that when a user request a resource like users/profile.html
, it can map that to the filesystem file /var/www/website/users/profile.html
, which is an actual file.
In Django, by contrast, there are no pre-written HTML files for Apache to find. Instead, all requests are directed to Django directly, which constructs the HTML file dynamically and returns that. Thus, Apache doesn't need a DocumentRoot
, it needs to know the location of Django's WSGI application file wsgi.py
, which is the "gateway" for sending HTTP requests to Django so that it can construct the right HTML file to return. This is specifed by the WSGIScriptAlias
directive and associated Apache configuration; e.g.
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
as given by the Django documentation on deploying Django with Apache.
TL;DR: You don't need DocumentRoot
, you need WSGIScriptAlias
for Django.
Upvotes: 2
Reputation: 7
I think you are asking for this:
ServerAdmin example@localhost
DocumentRoot /var/www/html
Upvotes: -1
Reputation: 4512
You point to project root; where wsgi.py
file is. From documentation:
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonHome /path/to/venv
WSGIPythonPath /path/to/mysite.com
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Static file are configured separately. Details here. Example (again, from docs):
Alias /robots.txt /path/to/mysite.com/static/robots.txt
Alias /favicon.ico /path/to/mysite.com/static/favicon.ico
Alias /media/ /path/to/mysite.com/media/
Alias /static/ /path/to/mysite.com/static/
<Directory /path/to/mysite.com/static>
Require all granted
</Directory>
<Directory /path/to/mysite.com/media>
Require all granted
</Directory>
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Upvotes: 10