modwsgi.txt 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. .. _howto-deployment-modwsgi:
  2. ==========================================
  3. How to use Django with Apache and mod_wsgi
  4. ==========================================
  5. Deploying Django with Apache_ and `mod_wsgi`_ is the recommended way to get
  6. Django into production.
  7. .. _Apache: http://httpd.apache.org/
  8. .. _mod_wsgi: http://code.google.com/p/modwsgi/
  9. mod_wsgi is an Apache module which can be used to host any Python application
  10. which supports the `Python WSGI interface`_, including Django. Django will work
  11. with any version of Apache which supports mod_wsgi.
  12. .. _python wsgi interface: http://www.python.org/dev/peps/pep-0333/
  13. The `official mod_wsgi documentation`_ is fantastic; it's your source for all
  14. the details about how to use mod_wsgi. You'll probably want to start with the
  15. `installation and configuration documentation`_.
  16. .. _official mod_wsgi documentation: http://code.google.com/p/modwsgi/
  17. .. _installation and configuration documentation: http://code.google.com/p/modwsgi/wiki/InstallationInstructions
  18. Basic Configuration
  19. ===================
  20. Once you've got mod_wsgi installed and activated, edit your ``httpd.conf`` file
  21. and add::
  22. WSGIScriptAlias / /path/to/mysite/apache/django.wsgi
  23. The first bit above is the url you want to be serving your application at (``/``
  24. indicates the root url), and the second is the location of a "WSGI file" -- see
  25. below -- on your system, usually inside of your project. This tells Apache
  26. to serve any request below the given URL using the WSGI application defined by that file.
  27. Next we'll need to actually create this WSGI application, so create the file
  28. mentioned in the second part of ``WSGIScriptAlias`` and add::
  29. import os
  30. import sys
  31. os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'
  32. import django.core.handlers.wsgi
  33. application = django.core.handlers.wsgi.WSGIHandler()
  34. If your project is not on your ``PYTHONPATH`` by default you can add::
  35. sys.path.append('/usr/local/django')
  36. just above the ``import`` line to place your project on the path. Remember to
  37. replace 'mysite.settings' with your correct settings file.
  38. See the :ref:`Apache/mod_python documentation<howto-deployment-modpython>` for
  39. directions on serving static media, and the `mod_wsgi documentation`_ for an
  40. explanation of other directives and configuration options you can use.
  41. Details
  42. =======
  43. For more details, see the `mod_wsgi documentation`_, which explains the above in
  44. more detail, and walks through all the various options you've got when deploying
  45. under mod_wsgi.
  46. .. _mod_wsgi documentation: http://code.google.com/p/modwsgi/wiki/IntegrationWithDjango