mod_wsgi.rst
This file
Path
docs/deploying/mod_wsgi.rst
80 lines · 2.7 KiB
Last changed by
Break up deployment docs into separate documents.Armin Ronacherbefore adoptionc64a4e0
History of this fileTake it
Break up deployment docs into separate documents.Armin Ronacherbefore adoptionc64a4e0
lines 1–80why, one step back1mod_wsgi (Apache)2=================34If you are using the `Apache`_ webserver you should consider using `mod_wsgi`_.56.. _Apache: http://httpd.apache.org/78Installing `mod_wsgi`9---------------------1011If you don't have `mod_wsgi` installed yet you have to either install it using12a package manager or compile it yourself.1314The mod_wsgi `installation instructions`_ cover installation instructions for15source installations on UNIX systems.1617If you are using ubuntu / debian you can apt-get it and activate it as follows::1819 # apt-get install libapache2-mod-wsgi2021On FreeBSD install `mod_wsgi` by compiling the `www/mod_wsgi` port or by using22pkg_add::2324 # pkg_add -r mod_wsgi2526If you are using pkgsrc you can install `mod_wsgi` by compiling the27`www/ap2-wsgi` package.2829If you encounter segfaulting child processes after the first apache reload you30can safely ignore them. Just restart the server.3132Creating a `.wsgi` file33-----------------------3435To run your application you need a `yourapplication.wsgi` file. This file36contains the code `mod_wsgi` is executing on startup to get the application37object. The object called `application` in that file is then used as38application.3940For most applications the following file should be sufficient::4142 from yourapplication import app as application4344If you don't have a factory function for application creation but a singleton45instance you can directly import that one as `application`.4647Store that file somewhere where you will find it again (eg:48`/var/www/yourapplication`) and make sure that `yourapplication` and all49the libraries that are in use are on the python load path. If you don't50want to install it system wide consider using a `virtual python`_ instance.5152Configuring Apache53------------------5455The last thing you have to do is to create an Apache configuration file for56your application. In this example we are telling `mod_wsgi` to execute the57application under a different user for security reasons:5859.. sourcecode:: apache6061 <VirtualHost *>62 ServerName example.com6364 WSGIDaemonProcess yourapplication user=user1 group=group1 threads=565 WSGIScriptAlias / /var/www/yourapplication/yourapplication.wsgi6667 <Directory /var/www/yourapplication>68 WSGIProcessGroup yourapplication69 WSGIApplicationGroup %{GLOBAL}70 Order deny,allow71 Allow from all72 </Directory>73 </VirtualHost>7475For more information consult the `mod_wsgi wiki`_.7677.. _mod_wsgi: http://code.google.com/p/modwsgi/78.. _installation instructions: http://code.google.com/p/modwsgi/wiki/QuickInstallationGuide79.. _virtual python: http://pypi.python.org/pypi/virtualenv80.. _mod_wsgi wiki: http://code.google.com/p/modwsgi/wiki/