我的环境是win7+python2.7.8+django1.6.4+apache2.2
废话不多说,直接进入正题:
下载对应的版本的mod_wsgi.so
第一步:添加mod_wsgi.so(记得对应的版本)到Apache2.2modules底下。
打开httpd.conf
第二步:添加Module,LoadModule wsgi_module modules/mod_wsgi.so
第三步:取注释,找到LoadModule vhost_alias_module modules/mod_vhost_alias.so删除注释。
第四步:直接看代码吧!
listen 8001 #第一个项目的监听端口 NameVirtualHost *:8001 #名字而已 <VirtualHost *:8001> DocumentRoot "F:/Workspaces_python/InvestigateSystem" #项目根目录路径 WSGIScriptAlias / "F:/Workspaces_python/InvestigateSystem/InvestigateSystem/wsgi.py" #项目wsgi文件的路径 <Directory "F:/Workspaces_python/InvestigateSystem"> #配置目录的权限?哪位大侠知道,请告诉一下,谢谢。 Order Deny,Allow Allow from all </Directory> Alias /static "F:/Workspaces_python/InvestigateSystem/static" #配置项目的静态文件路径 <Directory "F:/Workspaces_python/InvestigateSystem/static"> #同上? Options Indexes FollowSymLinks Order allow,deny Allow from all </Directory> </VirtualHost> listen 8002 #第二个项目的监听端口,除了监听端口其他配置基本一样 NameVirtualHost *:8002 <VirtualHost *:8002> DocumentRoot "F:/Workspaces_python/hospitalService" WSGIScriptAlias / "F:/Workspaces_python/hospitalService/hospitalService/wsgi.py" <Directory "F:/Workspaces_python/hospitalService"> Order Deny,Allow Allow from all </Directory> Alias /static "F:/Workspaces_python/hospitalService/static" <Directory "F:/Workspaces_python/hospitalService/static"> Options Indexes FollowSymLinks Order allow,deny Allow from all </Directory> </VirtualHost>
第五步:修改django项目中的原来的wsgi.py文件,看代码:
1 import os 2 import sys 3 4 sys.path.append('F:/Workspaces_python/InvestigateSystem') #这里的路径改成项目对应的路径就好了 5 6 os.environ['DJANGO_SETTINGS_MODULE'] = 'InvestigateSystem.settings' #这里的settings,你懂得! 7 os.environ['PYTHON_EGG_CACHE'] = '/tmp' 8 9 import django.core.handlers.wsgi 10 application = django.core.handlers.wsgi.WSGIHandler()
OK,到这里就基本上配置完成了,开启apache跑吧。