Apache部署Django项目(windows)
简介
由于最近python3.6没有mod_wsgi,所以将Python换成了3.5...啊浪费好多时间,等于少活了一段时间...TMD,留给有缘人看到我这篇博客吧..
首先最近一点时间mod_wsgi没有支持python3.6的所以换成3.5就可以了,
CP对应python版本,VC要和下载的Apache一样
安装前提
- python保证是3.5的64位,(目前一段时间).
- Apache (64)
- django版本(我是2.1.4)
- mod_wsgi版本要对应起来
文件分享
python解释器...持续更新中
Apache...
mod_wsgi模块安装
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
下载好放在python安装路径的scripts里面 切进去
D:python35Scripts> pip install mod_wsgi-4.5.24+ap24vc14-cp35-cp35m-win_amd64.whl
成功会有successful标示...
然后运行
D:python35Scripts> mod_wsgi-express module-config
得到输出的三个结果
LoadFile "d:/python35.dll"
LoadModule wsgi_module "d:/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
WSGIPythonHome "d:/python35"
Apache参数修改
将三个结果复制到D:Apacheconfighttpd.conf最下面
设置django项目和wsgi.py路径
WSGIScriptAlias / D:/projectname/projectname/wsgi.py
WSGIPythonPath D:/projectname
<Directory D:/projectname/projectname>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
端口
Listen 8000
ServerName localhost:8000
模板设置
DocumentRoot "D:/projectname/templates"
<Directory "D:/projectname/templates">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
在D:Apachein里面双击httpd.exe就可以运行了
在网址上输入127.0.0.1:8000就可以运行django项目了
命令
D:Apachein> httpd -k install D:Apachein> httpd -k start
install成功之后也可以使用net start xxx
静态文件
<Directory "D:/projectname/projectname/static/">
Require all granted
</Directory>
Alias /static/ "D:/projectname/projectname/static/"
...持续更新
Apache配置总结
LoadFile "d:/python35/python35.dll"
LoadModule wsgi_module "d:/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
WSGIPythonHome "d:/python35"
<VirtualHost *:8000>
#这里填写你的服务器ip地址
ServerName localhost
#设置工程中的wsgi路径(django项目里的wsgi.py文件)
#flask项目的话,需要自建wsgi.py文件,在把路径添加到此
WSGIScriptAlias / D:/Django/wufei/wufei/wsgi.py
#设置访问权限
<Directory D:/Django/wufei/wufei>
<Files wsgi.py>
#apache2.4及以上访问权限设置格式
Require all granted
</Files>
</Directory>
#静态文件夹权限
Alias /static D:/Django/wufei/static
<Directory D:/Django/wufei/static>
Require all granted
</Directory>
</VirtualHost>
WSGIPythonPath D:/Django/wufei
参考https://blog.csdn.net/dave_haijie/article/details/78060888