1.安装和配置Apache
下载Apache2.2.4: wget http://mirror.bjtu.edu.cn/apache//httpd/httpd-2.2.24.tar.gz
tar -xvf httpd-2.2.24.tar.gz
cd httpd-2.2.24
./configure --prefix=/usr/server/apache2/
make
make install
2.安装mod_wsgi
下载地址:wget http://modwsgi.googlecode.com/files/mod_wsgi-3.4.tar.gz
1)解压缩
sudo tar xvf mod_wsgi-3.4.tar.gz
2)配置mod_wsgi
cd mod_wsgi-3.4
./configure --enable-shared --with-apxs=/usr/server/apache2/bin/apxs --with-python=/usr/bin/python CFLAGS=-fPIC LDFLAGS=-L. #apache安装位置,python安装位置动态链接库位置
注意python版本问题,如果按照上面的路径/usr/bin/python安装出错的话,请更改--with-python为合适的位置:
./configure --enable-shared --with-apxs=/usr/server/apache2/bin/apxs --with-python=/application/app/Python-2.7.2/python CFLAGS=-fPIC LDFLAGS=-L.
3)编译执行
sudo make
sudo make install
3.配置Apache
在/usr/server/apache2/conf/httpd.conf中添加:
LoadModule wsgi_module modules/mod_wsgi.so #mod_wsgi.so的配置行
WSGIScriptAlias / "/application/search/test/wsgi.py" #wsgi文件的位置
WSGIPythonPath /application/search/lib/python2.7/site-packages #python site-packages安装的位置
<VirtualHost *:80>
Alias /favicon.ico /application/search/test/static/favicon.ico
<Directory "/application/search/test/">
Order Deny,Allow
Allow from all
</Directory>
Alias /media/ /application/search/test/media/
Alias /static/ /application/search/test/static/
<Directory /application/search/test/media>
Order deny,allow
Allow from all
IndexOptions FancyIndexing
</Directory>
<Directory /application/search/test/static/ >
Order deny,allow
Allow from all
IndexOptions FancyIndexing
</Directory>
</VirtualHost>
Order deny,allow
Allow from all
IndexOptions FancyIndexing
</Directory>
<Directory /application/search/test/static/ >
Order deny,allow
Allow from all
IndexOptions FancyIndexing
</Directory>
wsgi.py配置文件里面的内容是:
import sys
import os
import django.core.handlers.wsgi
sys.path.append('/application/search/test')
os.environ['DJANGO_SETTINGS_MODULE']='config.settings'
application = django.core.handlers.wsgi.WSGIHandler()
/usr/server/apache2/bin/apachectl start#启动apache