昨天折騰了一天在Windows下配置apache+mod_wsgi 沒搞定,今兒終於弄通了!話說這玩意在linux上挺簡單的吧 windows。。。說多了都是淚 html
系統:Win7 64位 環境變量略,注意要配置 PYTHONHOME python
軟件:安裝過程略 linux
Apache 2.4.9 64位 apache
python 2.7.6 64位 django
Django 1.6.4 windows
mod_wsgi mod_wsgi-3.5.ap24.win-amd64-py2.7.zip(注意對應版本) 瀏覽器
注:Apache 必須選擇2.4版本,2.2版本我折磨一天沒通,歡迎小白鼠繼續測試... app
把 mod_wsgi-3.5.ap24.win-amd64-py2.7.zip解壓丟到apahce工做目錄下的modules目錄 ide
如: C:\Apache24\modules 測試
修改 apahce 配置文件 httpd.conf
在
# Example:
# LoadModule foo_module modules/mod_foo.so
#
後添加
LoadModule wsgi_module modules/mod_wsgi.so
啓動測試,查看error.log沒有問題繼續
c:\Apache24\bin\httpd.exe -w -n "Apache2.4" -k restart
如今 設你的Django項目主目錄爲 F:/mysite
在 apahce 配置文件 httpd.conf最後面加上
Include "f:/mysite/apache/apache_django_wsgi.conf"
在 項目 主目錄 裏增長apache文件夾
1. 增長文件apache_django_wsgi.conf
內容以下,按實際狀況修改:
# 設置django admin靜態資源的訪問路徑 Alias /static/ "F:/mysite/static/" <Directory "F:/mysite/static"> Options All AllowOverride All Require all granted </Directory> # 設置root,不要使用"^/" WSGIScriptAlias / "F:/mysite/apache/django.wsgi" WSGIPythonPath F:/mysite/apache <Directory "F:/mysite/apache"> Options All AllowOverride All Require all granted </Directory> <Directory "F:/mysite"> Options All AllowOverride All Require all granted </Directory>
2. 增長文件django.wsgi
內容以下,按實際狀況修改:
import os import sys #Calculate the path based on the location of the WSGI script. apache_configuration= os.path.dirname(__file__) project = os.path.dirname(apache_configuration) workspace = os.path.dirname(project) sys.path.append(project) #這個路徑是項目主目錄,如F:/mysite,必定要加上 os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings' import django.core.handlers.wsgi application = django.core.handlers.wsgi.WSGIHandler()
再次啓動測試
c:\Apache24\bin\httpd.exe -w -n "Apache2.4" -k restart
瀏覽器輸入:localhost
It worked! Congratulations on your first Django-powered page. Of course, you haven't actually done any work yet. Next, start your first app by running python manage.py startapp [appname]. You're seeing this message because you have DEBUG = True in your Django settings file and you haven't configured any URLs. Get to work!
---------------------------END------------------------------