apache与django的整合

Ubuntu下apache跟Django的整合
1. 下载mod_python

http://www.modpython.org/

Linux一般是以源码的形式提供,对下载的源码需要编译方可使用,先下载下来备用

2. 编译mod_python

准备:
1)需要apache的开发环境apxs

sudo apt-get install apache2-dev

自动安装以后的路径:/usr/bin/apxs2

2)安装python的开发环境

sudo apt-get install python-dev

3. 配置和安装mod_python

完成以上两步以后,将下载下来的mod_python解压,在doc-html中有详细的安装文档,按照其中的指导来安装
依次执行下面的命令行,如果没有出现错误基本上就没问题了
./configure --with-apxs=/usr/bin/apxs2
./configure --with-python=/usr/bin/python2.5
./configure --with-mutex-dir=/var/lock/apache2/mod_python
./configure --with-max-locks=32

接下来编译
$make
$sudo make install
如果顺利的话,就算安装成功了。在执行sudo make install的过程中有类似下面的输出提示:
Now don't forget to edit your main config and add
LoadModule python_module /usr/lib/apache2/modules/mod_python.so
and if your configuration uses ClearModuleList, then also
AddModule mod_python.c

记住把LoadModule python_module /usr/lib/apache2/modules/mod_python.so加到apache的配置文件中。

4. 配置apache

apache2.conf是一个总的配置文件,我们不去修改它,每个站点各自的配置文件都建立了一个软连接到sites-enabled,上一篇已经说过了。自定义的公共配置我们就放到httpd.conf中,内容如下:

LoadModule python_module /usr/lib/apache2/modules/mod_python.so
PythonOption mod_python.mutex_directory "/var/lock/apache2/"
PythonOption mod_python.mutex_locks 8

5. 配置站点

<VirtualHost 192.168.0.101:80>
ServerAdmin zhouzcy@gmail.com
ServerName www.newtest.com
DocumentRoot /home/dooluu/share/newtest
<Directory /home/dooluu/share/newtest>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
Alias /images/ "/home/dooluu/share/newtest/images/"
<Directory "/home/dooluu/share/newtest/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/dooluu/share/newtest下,即 diango-admin.py创建的工程,那么在PythonPath指定为/home/dooluu/share
<Location /^(images)>
SetHandler python-program
PythonPath "['/home/dooluu/share'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE newtest.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>

6. 启动django
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值