How to install mod_wsgi for apache and django?

I know that there is already a lot of information on this topic, but they are rather clumsy, not so simple and expressive. Can someone explain to me how to use djangoboth with mod_wsgiand apache?

+5
source share
3 answers

mod_wsgi is not particularly suitable for working with Python WSGI applications, or, if you prefer, there are more pythonic ways to run your Django instance.

First, I would suggest that understanding the Apache request processing model requires a lot of effort and its proper configuration, especially with regard to mod_wsgi. If you have not configured or enabled the use of Apache, I would recommend that you take a look at Spawning or Green Unicorn , for a nginx proxy, for example, @Neo.

Spawning and shooting are ridiculously fast, they do not require you to compile Apache using a special Python interpreter and provide support for gradually updating the code base on the fly, intercepting Django and other useful properties out of the box. nginx, Spawning and gunicorn have a simple processing model, they are completely independent of each other, so you get a more transparent architecture that is easier to maintain and control.

Django , Django , , .

, @home.

+9

Django, , . http://blog.stannard.net.au/2010/12/11/installing-django-with-apache-and-mod_wsgi-on-ubuntu-10-04/

,

  • ( Nginx) 80.
  • apache .
  • django apache mod_wsgi
  • Reverseproxy /- apache + mod_wsgi/django

, .

+5

This is how I do it on my Mac, with Apache, Python and Django from Mac ports. This is not necessarily the best approach, but it works for me.

I have the following top level directories:

  • lib: python code with settings.py parameters in the lib / settings.py folder
  • static: material that Apache should serve, for example. Media and CSS.
  • tools: development tools, for example. deployment scenarios.

So, here's the Apache config for an example site, and then see the Django WSGI script below:

<VirtualHost *:80>
    # Stuff to served statically is in media directory
    DocumentRoot /Library/WebServer/mysite/static

    ServerName mysite.local

    # Redirect to homepage action
    RewriteEngine on
    RewriteRule ^/$ /mysite/ [R,L]

    # Static dirs first
    Alias /static/ /Library/WebServer/mysite/static/

    <Directory "/Library/WebServer/mysite/static/">
        Order allow,deny
        Allow from all
    </Directory>    

    # Now everything else goes to Django    
    WSGIDaemonProcess mysite-django.local processes=1 threads=5 maximum-requests=0 display-name=%{GROUP} python-path=/Library/WebServer/mysite/lib python-eggs=/tmp
    WSGIProcessGroup mysite-django.local
    WSGIScriptAlias / /Library/WebServer/mysite/lib/apache/django_wsgi.py

    <Directory "/Library/WebServer/mysite/lib/apache">
        Order allow,deny
        Allow from all
    </Directory>    

</VirtualHost>

Django WGCI script is located in lib / apache / django_wsgi.py:

import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
+3
source

All Articles