很多教程都是在linux上搭建,windows上似乎天生不太適合,但是我還是願意試試這個坑。
首先 交代一下自己的環境
python3.5.2 64位
django 1.10.3
apache 2.4 64位
windows 10
重點在apache上。
python 和django 相信有興趣看這篇文章的基本上也都已經了解了。
******************分割線*******************************************************
安裝Apache2.4
地址:http://www.apachelounge.com/download/
下載:vc_redist.x64.exe 直接安裝 vc_redist_x64/86.exe.
下載:httpd-2.4.17-win64-VC14.zip
配置環境變量:path增加D:\Apache24\bin;
解壓到指定目錄 修改配置文件: http.conf (下面內容中的ServerRoot改成你自己的實際Apche解壓路徑)
ServerRoot "D:/Apache24" …… Listen 127.0.0.1:8081 #修改端口號 …… ServerName www.example.com:8081 …… DocumentRoot "D:/Apache24/htdocs" <Directory "D:/Apache24/htdocs"> …… ScriptAlias /cgi-bin/ "D:/Apache24/cgi-bin/" …… <Directory "D:/Apache24/cgi-bin"> AllowOverride None Options None Require all granted </Directory>
啟動apache服務:
cmd>httpd
http://127.0.0.1:8081/index.html
It works!
apache配置成功
******************分割線*******************************************************
安裝mod_wsgi先安裝:pip install wheel
安裝mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl
下載:mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl
地址:http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
pip 安裝:pip install mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl
******************分割線*******************************************************
配置Apache2.4、mod_wsgi、django項目工程
1. 將C:\Python35\mod_wsgi.so 拷貝至 D:\Apache24\modules下
(mod_wsgi.so 只有mod_wsgi-4.4.23+ap24vc14-cp35-cp35m-win_amd64.whl安裝成功后才能找到)
2.修改apache2.4的http.conf文件:
#添加mod_wsgi.so 模塊
LoadModule wsgi_module modules/mod_wsgi.so
3.配置django項目 修改http.conf
#添加mod_wsgi.so 模塊
LoadModule wsgi_module modules/mod_wsgi.so#指定靜態資源路徑
Alias /statics/ F:/pydj/newsCollection/toutiao/statics/
<Directory F:/pydj/newsCollection/toutiao/statics>
Require all granted
</Directory>
#指定newsCollection項目的wsgi.py配置文件路徑
WSGIScriptAlias / F:/pydj/newsCollection/newsCollection/wsgi.py#指定項目路徑
WSGIPythonPath F:/pydj/newsCollection
<Directory F:/pydj/newsCollection/newsCollection>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
*************分割線************************************************************wsgi.py內容:import os os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myweb.settings") from django.core.wsgi import get_wsgi_application application = get_wsgi_application()#注意上面的myweb,是改成自己的項目名稱,比如上圖中 newsCollection。參考上上圖中的目錄結構。*************分割線************************************************************配置django工程setting.pyALLOWED_HOSTS = ['127.0.0.1', 'localhost']最后告訴一點 Apche 啟動的時候報錯會有log, httpd-2.4.23-x64-vc14-r3\Apache24\logs 目錄下 error信息,慢慢排錯