Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #11229 -- Updated the mod_wsgi deployment documentation to avoi…

…d references to mod_python and techniques that are not recommended or required for mod_wsgi. Thanks to Graham Dumpleton for the suggestion and guidance.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@11249 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 9fd19c01611e5ed1ed64bbeb462ab96499d72a6c 1 parent 49f0a4b
Russell Keith-Magee authored July 16, 2009

Showing 1 changed file with 118 additions and 69 deletions. Show diff stats Hide diff stats

  1. 187  docs/howto/deployment/modwsgi.txt
187  docs/howto/deployment/modwsgi.txt
... ...
@@ -1,69 +1,118 @@
1  
-.. _howto-deployment-modwsgi:
2  
-
3  
-==========================================
4  
-How to use Django with Apache and mod_wsgi
5  
-==========================================
6  
-
7  
-Deploying Django with Apache_ and `mod_wsgi`_ is the recommended way to get
8  
-Django into 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`_, including Django. Django will work
15  
-with any version of Apache which supports mod_wsgi.
16  
-
17  
-.. _python wsgi interface: http://www.python.org/dev/peps/pep-0333/
18  
-
19  
-The `official mod_wsgi documentation`_ is fantastic; it's your source for all
20  
-the details about how to use mod_wsgi. You'll probably want to start with the
21  
-`installation and configuration documentation`_.
22  
-
23  
-.. _official mod_wsgi documentation: http://code.google.com/p/modwsgi/
24  
-.. _installation and configuration documentation: http://code.google.com/p/modwsgi/wiki/InstallationInstructions
25  
-
26  
-Basic Configuration
27  
-===================
28  
-
29  
-Once you've got mod_wsgi installed and activated, edit your ``httpd.conf`` file
30  
-and add::
31  
-
32  
-    WSGIScriptAlias / /path/to/mysite/apache/django.wsgi
33  
-
34  
-The first bit above is the url you want to be serving your application at (``/``
35  
-indicates the root url), and the second is the location of a "WSGI file" -- see
36  
-below -- on your system, usually inside of your project. This tells Apache
37  
-to serve any request below the given URL using the WSGI application defined by that file.
38  
-
39  
-Next we'll need to actually create this WSGI application, so create the file
40  
-mentioned in the second part of ``WSGIScriptAlias`` and add::
41  
-
42  
-    import os
43  
-    import sys
44  
-
45  
-    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
46  
-
47  
-    import django.core.handlers.wsgi
48  
-    application = django.core.handlers.wsgi.WSGIHandler()
49  
-
50  
-If your project is not on your ``PYTHONPATH`` by default you can add::
51  
-
52  
-    sys.path.append('/usr/local/django')
53  
-
54  
-just above the final ``import`` line to place your project on the path. Remember to
55  
-replace 'mysite.settings' with your correct settings file, and '/usr/local/django'
56  
-with your own project's location.
57  
-
58  
-See the :ref:`Apache/mod_python documentation<howto-deployment-modpython>` for 
59  
-directions on serving static media, and the `mod_wsgi documentation`_ for an 
60  
-explanation of other directives and configuration options you can use.
61  
-
62  
-Details
63  
-=======
64  
-
65  
-For more details, see the `mod_wsgi documentation`_, which explains the above in
66  
-more detail, and walks through all the various options you've got when deploying
67  
-under mod_wsgi.
68  
-
69  
-.. _mod_wsgi documentation: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango
  1
+.. _howto-deployment-modwsgi:
  2
+
  3
+==========================================
  4
+How to use Django with Apache and mod_wsgi
  5
+==========================================
  6
+
  7
+Deploying Django with Apache_ and `mod_wsgi`_ is the recommended way to get
  8
+Django into 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`_, including Django. Django will work
  15
+with any version of Apache which supports mod_wsgi.
  16
+
  17
+.. _python wsgi interface: http://www.python.org/dev/peps/pep-0333/
  18
+
  19
+The `official mod_wsgi documentation`_ is fantastic; it's your source for all
  20
+the details about how to use mod_wsgi. You'll probably want to start with the
  21
+`installation and configuration documentation`_.
  22
+
  23
+.. _official mod_wsgi documentation: http://code.google.com/p/modwsgi/
  24
+.. _installation and configuration documentation: http://code.google.com/p/modwsgi/wiki/InstallationInstructions
  25
+
  26
+Basic Configuration
  27
+===================
  28
+
  29
+Once you've got mod_wsgi installed and activated, edit your ``httpd.conf`` file
  30
+and add::
  31
+
  32
+    WSGIScriptAlias / /path/to/mysite/apache/django.wsgi
  33
+
  34
+The first bit above is the url you want to be serving your application at (``/``
  35
+indicates the root url), and the second is the location of a "WSGI file" -- see
  36
+below -- on your system, usually inside of your project. This tells Apache
  37
+to serve any request below the given URL using the WSGI application defined by that file.
  38
+
  39
+Next we'll need to actually create this WSGI application, so create the file
  40
+mentioned in the second part of ``WSGIScriptAlias`` and add::
  41
+
  42
+    import os
  43
+    import sys
  44
+
  45
+    os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
  46
+
  47
+    import django.core.handlers.wsgi
  48
+    application = django.core.handlers.wsgi.WSGIHandler()
  49
+
  50
+If your project is not on your ``PYTHONPATH`` by default you can add::
  51
+
  52
+    sys.path.append('/usr/local/django')
  53
+
  54
+just above the final ``import`` line to place your project on the path. Remember to
  55
+replace 'mysite.settings' with your correct settings file, and '/usr/local/django'
  56
+with your own project's location.
  57
+
  58
+Serving media files
  59
+===================
  60
+
  61
+Django doesn't serve media files itself; it leaves that job to whichever Web
  62
+server you choose.
  63
+
  64
+We recommend using a separate Web server -- i.e., one that's not also running
  65
+Django -- for serving media. Here are some good choices:
  66
+
  67
+    * lighttpd_
  68
+    * Nginx_
  69
+    * TUX_
  70
+    * A stripped-down version of Apache_
  71
+    * Cherokee_
  72
+
  73
+If, however, you have no option but to serve media files on the same Apache
  74
+``VirtualHost`` as Django, you can set up Apache to serve some URLs as
  75
+static media, and others using the mod_wsgi interface to Django.
  76
+
  77
+This example sets up Django at the site root, but explicitly serves ``robots.txt``,
  78
+``favicon.ico``, any CSS file, and anything in the ``/media/`` URL space as a static
  79
+file. All other URLs will be served using mod_wsgi::
  80
+
  81
+    Alias /robots.txt /usr/local/wsgi/static/robots.txt
  82
+    Alias /favicon.ico /usr/local/wsgi/static/favicon.ico
  83
+
  84
+    AliasMatch /([^/]*\.css) /usr/local/wsgi/static/styles/$1
  85
+
  86
+    Alias /media/ /usr/local/wsgi/static/media/
  87
+
  88
+    <Directory /usr/local/wsgi/static>
  89
+    Order deny,allow
  90
+    Allow from all
  91
+    </Directory>
  92
+
  93
+    WSGIScriptAlias / /usr/local/wsgi/scripts/django.wsgi
  94
+
  95
+    <Directory /usr/local/wsgi/scripts>
  96
+    Order allow,deny
  97
+    Allow from all
  98
+    </Directory>
  99
+
  100
+.. _lighttpd: http://www.lighttpd.net/
  101
+.. _Nginx: http://wiki.codemongers.com/Main
  102
+.. _TUX: http://en.wikipedia.org/wiki/TUX_web_server
  103
+.. _Apache: http://httpd.apache.org/
  104
+.. _Cherokee: http://www.cherokee-project.com/
  105
+
  106
+More details on configuring a mod_wsgi site to serve static files can be found
  107
+in the mod_wsgi documentation on `hosting static files`_.
  108
+
  109
+.. _hosting static files: http://code.google.com/p/modwsgi/wiki/ConfigurationGuidelines#Hosting_Of_Static_Files
  110
+
  111
+Details
  112
+=======
  113
+
  114
+For more details, see the `mod_wsgi documentation on Django integration`_,
  115
+which explains the above in more detail, and walks through all the various
  116
+options you've got when deploying under mod_wsgi.
  117
+
  118
+.. _mod_wsgi documentation on Django integration: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango

0 notes on commit 9fd19c0

Please sign in to comment.
Something went wrong with that request. Please try again.