标签:
Win7/Apache/Python2.7/Django1.9部署Web
环境:
Windows7
Apache httpd-2.4.16-win64-VC14
Python2.7.11
Django1.9.7
1、安装Apache
1)下载相关组件
步骤参照http://blog.csdn.net/qq_15096707/article/details/47319545
从官网 http://httpd.apache.org 下载Apache
Files for microsoft windows -> Apache Lounge -> httpd-2.4.16-win64-VC14
下载完成之后,我们要做的是解压该文件到自定义的目录,找到Apache24中的bin目录,打开 ApacheMonitor.exe
如果ApacheMonitor.exe不能运行,提示缺少文件,如缺少 vcruntime140.dll文件,安装响应的VC库,我安装了vc_redist.x64(VC2015)
2)修改httpd.conf配置文件
37行: ServerRoot "apache目录" (e.g. ‘c:/apache24‘ 改为 e:/apache34)
ServerRoot "e:/Apache24"
219行:ServerName 服务器名称 (e.g demo.app.com or 127.0.0.1)去掉# (这里也可以填 localhost)
ServerName 127.0.0.1
243行: DocumentRoot 修改网站根目录地址
DocumentRoot "e:/Apache24/htdocs"
244行:<Directory "网站根目录地址">
<Directory "e:/Apache24/htdocs">
360行:ScriptAlias /cgi-bin/ "apache目录+/cgi-bin/"
ScriptAlias /cgi-bin/ "e:/Apache24/cgi-bin/"
376行:<Directory "apache目录+/cgi-bin/">
<Directory "e:/Apache24/cgi-bin">
3)使用命令行cmd安装Apache服务
在管理员模式下启动命令行,然后cd到apache/bin目录下运行
httpd -k install
如果重启或卸载
#重启服务
httpd -k restart
#卸载服务
httpd -k uninstall
4)启动和测试
启动Apache服务成功后,打开 ApacheMonitor.exe,点击start,成功启动服务
为了测试是否真的成功,可以在浏览器上输入 http://localhost/
出现“It works”
2、部署Django
参照了http://blog.csdn.net/yingmutongxue/article/details/43985559
1)下载mod_wsgi组件
下载链接http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
选择对应python2.7和64位系统的版本
mod_wsgi-4.4.23+ap24vc9-cp27-cp27m-win_amd64.whl
解压出mod_wsgi.so后放于apache24/module文件夹下
一开始我下载了该组件的错误版本导致apache服务无法启动
在命令行启动,输入命令
httpd -w -n “apache2.4” -k start
会在屏幕上显示错误信息
Cannot load modules/mod_wsgi.so into server
换成正确版本后不再报错
2)修改配置文件httpd.conf
#添加mod_wsgi.so模块
LoadModule wsgi_module modules/mod_wsgi.so
在文档尾部添加
#指定myweb项目的wsgi.py配置文件路径
WSGIScriptAlias / "E:/code/wljk_workshop/wljk_workshop/wsgi.py"
#指定项目路径
WSGIPythonPath "E:/code/wljk_workshop"
<Directory E:/code/wljk_workshop>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
Alias /statics E:/code/wljk_workshop/statics
<Directory E:/code/wljk_workshop/statics>
Require all granted
</Directory>
3)设置settings.py
DEBUG = False
TEMPLATE_DEBUG = False
ALLOWED_HOSTS = [‘127.0.0.1‘, ‘localhost‘]
4)排错
以上设置后还是无法启动服务器,查看apache24/logs/error
[Thu Jun 30 18:30:54.678499 2016] [mpm_winnt:notice] [pid 1776:tid 300] AH00455: Apache/2.4.16 (Win64) mod_wsgi/4.4.23 Python/2.7.11 configured -- resuming normal operations
[Thu Jun 30 18:30:54.678499 2016] [mpm_winnt:notice] [pid 1776:tid 300] AH00456: Apache Lounge VC14 Server built: Jul 22 2015 13:24:19
[Thu Jun 30 18:30:54.678499 2016] [core:notice] [pid 1776:tid 300] AH00094: Command line: ‘E:\\Apache24\\bin\\httpd.exe -d E:/Apache24‘
[Thu Jun 30 18:30:54.678499 2016] [mpm_winnt:notice] [pid 1776:tid 300] AH00418: Parent: Created child process 5868
ImportError: No module named site
[Thu Jun 30 18:30:55.068500 2016] [mpm_winnt:crit] [pid 1776:tid 300] AH00419: master_main: create child process failed. Exiting.
报错AH00419: master_main: create child process failed
参考http://stackoverflow.com/questions/34440078/apache24-x86-vc9-with-mod-wsgi-says-ah00419-master-main-create-child-process/35767105
配置中添加:
WSGIPythonPath "E:/code/wljk_workshop;E:/Python27/Lib;E:/Python27/Lib/site-packages;E:/Python27/DLLs"
WSGIPythonHome "E:/Python27"
服务器启动成功,访问网站成功。
但是此时只能本地访问,在其他终端访问时返回400 Bad request
修改settings.py
ALLOWED_HOSTS = [‘*‘]
访问成功
Windows下Apache部署Django过程记录
标签:
原文地址:http://www.cnblogs.com/todorov/p/5635432.html