1 | .. _howto-deployment-modwsgi:
|
---|
2 |
|
---|
3 | ==========================================
|
---|
4 | How to use Django with Apache and mod_wsgi
|
---|
5 | ==========================================
|
---|
6 |
|
---|
7 | Apache_ with `mod_wsgi`_ is one of the reccomended ways for using Django in
|
---|
8 | production.
|
---|
9 |
|
---|
10 | .. _Apache: http://httpd.apache.org/
|
---|
11 | .. _mod_wsgi: http://code.google.com/p/modwsgi/
|
---|
12 |
|
---|
13 | mod_wsgi is an Apache module which can be used to host any Python application
|
---|
14 | which supports the Python WSGI interface (`PEP 333`_), including Django. Django
|
---|
15 | will work with any version of Apache which supports mod_wsgi.
|
---|
16 |
|
---|
17 | .. _PEP 333: http://www.python.org/dev/peps/pep-0333/
|
---|
18 |
|
---|
19 | Basic Configuration
|
---|
20 | ===================
|
---|
21 |
|
---|
22 | First make sure you have Apache installed, and mod_wsgi installed and activated.
|
---|
23 | Next edit your ``httpd.conf`` file and add::
|
---|
24 |
|
---|
25 | WSGIScriptAlias / /usr/local/django/mysite/apache/django.wsgi
|
---|
26 |
|
---|
27 | Where the first path is the url you want to be serving your application at (/
|
---|
28 | indicates the root url), and the second is the location of a WSGI file (to be
|
---|
29 | explained momentarily) on your system, usually inside of your project. This
|
---|
30 | will tell Apache to serve any request at that URL using WSGI, configured with
|
---|
31 | that file. Next we create our WSGI file, at the location we just indicated and
|
---|
32 | put in it::
|
---|
33 |
|
---|
34 | import os
|
---|
35 | import sys
|
---|
36 |
|
---|
37 | os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
|
---|
38 |
|
---|
39 | import django.core.handlers.wsgi
|
---|
40 | application = django.core.handlers.wsgi.WSGIHandler()
|
---|
41 |
|
---|
42 | If your project is not on your PYTHONPATH by default you can add::
|
---|
43 |
|
---|
44 | sys.path.append('/usr/local/django')
|
---|
45 |
|
---|
46 | to place it on the path. Also replace 'mysite.settings' with your settings file.
|
---|
47 |
|
---|
48 | See the :ref:`Apache/mod_python documentation<howto-deployment-modpython>` for
|
---|
49 | directions on serving static media, and the `mod_wsgi documentation`_ for an
|
---|
50 | explanation of other directives and configuration options you can use.
|
---|
51 |
|
---|
52 | .. _mod_wsgi documentation: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
|
---|