linux apache发布django代码
1.yum install httpd
2.yum install python
3.yum install mod_python
注意:
LoadModule python_module modules/mod_python.so这个不用添加,因为在/etc/httpd/conf.d/python.conf 已经配置好
#/etc/init.d/httpd restart
#导入模块
#python
Python 2.4.3 (#1, Jan 9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mod_python
4.安装django
http://www.djangoproject.com/
#导入模块
#python
Python 2.4.3 (#1, Jan 9 2013, 06:49:54)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import django
#cd /var/www/html
5.配置apache虚拟目录(虚拟目录有两种,一种是基于目录,另一种是基于域名)
基于虚拟目录
web_info 是自己建立的目录
vi /etc/httpd/conf/httpd.conf
<VirtualHost *:80>
<Location "/">
SetHandler python-program
PythonPath "['/var/www/html/'] + sys.path"
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE web_info.settings
PythonAutoReload Off
PythonDebug On
</Location>
</VirtualHost>
#/etc/init.d/httpd restart
在/var/www/html目录下面的test.py写入:
from mod_python import apache
def handler(req):
req.write("Hello World!")
return apache.OK
浏览器测试
http://192.168.30.203
Hello World!
说明配置正常
=================================================
虚拟主机基于域名访问:
vi /etc/httpd/conf/httpd.conf
NameVirtualHost *:80###去掉注释
添加如下配置:
<VirtualHost *:80>
ServerAdmin admin@ccc.com
DocumentRoot /var/www/html
ServerName www.203.com
<Directory "/var/www/html">
AllowOverride FileInfo
AddHandler mod_python .py
PythonHandler test
PythonDebug On
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
#/etc/init.d/httpd restart
##修改下本地hosts文件IP映射成www.203.com##
浏览器访问: