Ubuntu 9.10+ apache2.2 +Django的配置

1.首先安装mod_python

apt-get install libapache2-mod-python2.6

(Ubuntu 9.10默认安装的是python 2.6版,如果是2.5可改为 libapache2-mod-python2.5)

2.配置apache 1)

1) vi /etc/apache2/httpd.conf

2)添加如下代码

LoadModule python_module /usr/lib/apache2/modules/mod_python.so

PythonOption mod_python.mutex_directory "/var/lock/apache2/"

PythonOption mod_python.mutex_locks 8

3.配置站点

1)cd /etc/apache2/sites-available

2)新建站点文件 newsite,添加如下代码

<VirtualHost *:80>

ServerAdmin

ServerName www.newtest.com

DocumentRoot /home/userasin/django_projects/myproject

<Directory /home/userasin/django_projects/myproject>

Options Indexes FollowSymLinks MultiViews

AllowOverride None

Order allow,deny

allow from all

</Directory>

Alias /images/ "/home/userasin/django_projects/myproject/images/"

<Directory "/home/userasin/django_projects/myproject/images/">

Options Indexes MultiViews FollowSymLinks

AllowOverride None

Order deny,allow

Allow from all

</Directory>

#control images

<Location /images/>

Order allow,deny

allow from all

</Location>

#除了图片都转发到django,PythonPath指定站点的根目录,这里站点在/home/userasin/django_projects/myproject下,

#即diango-admin.py创建的工程,那么在PythonPath指定为/home/userasin/django_projects/

<Location "/">

SetHandler python-program

PythonPath "['/home/userasin/django_projects'] + sys.path"

PythonHandler django.core.handlers.modpython

#diango-admin.py创建的工程的名字+".settings"

SetEnv DJANGO_SETTINGS_MODULE myproject.settings

PythonAutoReload On

PythonDebug On

</Location>

ErrorLog /var/log/apache2/newtest.log

# Possible values include: debug, info, notice, warn, error, crit,

# alert, emerg.

LogLevel warn

CustomLog /var/log/apache2/newtest.log combined

</VirtualHost>