Example 4 with WSGIDaemonProcess Django 1.5 ¶
Introduction ¶
Comme le bon vin, Django se bonifie avec le temps. Mieux encore, il se simplifie ! C’est notamment le cas pour son intégration avec Apache 2 via le module WSGI.
Un précédent article proposait une démarche permettant de servir une application Django 1.3 avec Apache 2 et le module WSGI. Depuis, Django est passé en version 1.4 puis 1.5. L’occasion de remettre ça !
L’environnement utilisé pour cet article repose sur la distribution Debian Wheezy 7.1 amd64. On y a ajouté les paquets apache2, libapache2-mod-wsgi et Django 1.5.4.
Arborescence ¶
idreammicro
|_ helloworld
| |_ __init__.py
| |_ models.py
| |_ tests.py
| |_ views.py
|_ idreammicro
| |_ __init.py__
| |_ settings.py
| |_ urls.py
| |_ wsgi.py
|_ manage.py
Virtual Host Apache ¶
On choisit de créer un serveur virtuel dédié au projet Django.
Django 1.4 a introduit une amélioration du support WSGI, en embarquant une application WSGI dans le fichier idreammicro/wsgi.py.
Les opérations suivantes nécessitent d’avoir les droits d’administration.
On crée le fichier /etc/apache2/sites-available/idreammicro.
Warning
Pas de traitement des fichiers static !
Warning
Pas d’environnement virtuel !
Warning
apparemment utilisation d’Apache 2.2 et non 2.4
1 <VirtualHost *:80>
2
3 ServerName django
4 ServerAlias django
5
6 DocumentRoot /home/jlesech/www-django/idreammicro
7
8 <Directory /home/jlesech/www-django/idreammicro>
9 Order allow,deny
10 Allow from all
11 </Directory>
12
13 WSGIDaemonProcess django processes=2 threads=15 display-name=%{GROUP} python-path=/home/jlesech/www-django/idreammicro
14 WSGIProcessGroup django
15
16 WSGIScriptAlias / /home/jlesech/www-django/idreammicro/idreammicro/wsgi.py
17
18 <Directory /home/jlesech/www-django/idreammicro/idreammicro>
19 Order allow,deny
20 Allow from all
21 </Directory>
22
23 ErrorLog ${APACHE_LOG_DIR}/idreammicro_error.log
24
25 # Possible values include: debug, info, notice, warn, error, crit,
26 # alert, emerg.
27 LogLevel warn
28
29 CustomLog ${APACHE_LOG_DIR}/idreammicro_access.log combined
30
31 </VirtualHost>
On active le nouveau serveur virtuel:
a2ensite django
Dans le fichier /etc/hosts, on ajoute un host (ligne 3):
127.0.0.1 localhost
127.0.1.1 i7
127.0.0.1 django