-
下载安装apache
- 打开apache官网http://www.apache.org/

- 点击右上角Download,出现以下界面 ,这里是各镜像服务器,随便找一个,这里用的是推荐版。

- 出现目录列表,这些是apache的项目列表,我也不明白apahce为什么用这种方式浏览。

- 点“httpd",出现以下界面

- 点红框部分,出现如下界面

- 进入如下界面后,选择第一项ApacheHaus,这是个第三方下载平台,在它的网站下载独立的Apache会是一个压缩包。另外四个中,第二个也是独立的Apache下载地址,另外三个是集成开发环境。

- 在新的界面中,会发现VC9和VC11字样,通过阅读相关内容得知,VC9是指用VS2008编译的代码,而VC11是用VS2012编译的,而用VS2012编译的无法在Windows XP和Server 2003中使用。

2.安装apache
把下载文件解压到你要安装目录,如:d:
安装服务:打开cmd 进入apache\bin 文件 执行httpd.exe -k install -n Apache2.4
该命令的意思是,安装apache服务,并将该服务名称命名为Apache2.4(你也可以改成别的)
如果报一下错误
sock: could not bind to address [::]:443
(OS 10013)以一种访问权限不允许的方式做了一个访问套接字的尝试。 : AH00072: make_
sock: could not bind to address 0.0.0.0:443
说明你的443端口已经呗占用,则需要修改 httpd-ssl.conf或httpd-ahssl.conf中的443端口改成其它端口号,如果用不到443端口(用于https)可以直接在httpd.config中,直接屏蔽掉对应的配置,如下:
<IfModule ssl_module>
#Include conf/extra/httpd-ssl.conf
#Include conf/extra/httpd-ahssl.conf
#SSLRandomSeed startup builtin
#SSLRandomSeed connect builtin
</IfModule>
启动apache 服务能正常启动说明安装成功。
3.安装mod_wsgi
设置环境变量“MOD_WSGI_APACHE_ROOTDIR”为Apache安装目录 如D:\Apache24
然后运行pip install mod_wsgi 进行安装,下载过程中如果遇到如下错误:
building 'mod_wsgi.server.mod_wsgi' extension
error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat).
Get it from http://aka.ms/vcpython27
按指定目录下载vcpython27并安装就可以了。
不知为什么用pip自动安装的匹配的是mod_wsgi 4.5.23 但安装一直失败,报如下错误
D:\Heatnetwork\Apache24/include\httpd.h(44) : fatal error C1083: Cannot open inc
lude file: 'ap_config.h': No such file or directory
于是我下载了“mod_wsgi-4.5.22+ap24vc9-cp27-cp27m-win_amd64”的版本再进行安装成功。下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
4.配置mod_wsgi
网上有的说解压mod_wsgi对应的whl文件找到mod_wsgi.so文件放到apache安装目录里面 modules 目录下,但我解压后怎么也找不到mod_wsgi.so文件。找到其它方法
进行安装在安装成功后在python的安装目录的\scripts文件夹下运行 mod_wsgi-express module-config
输出如下:

把输出中的"mod_wsgiNone"改成“mod_wsgi”, 然后拷贝到httpd.conf文件的中,如下图:

5.新建wsgi文件,即下面要配置的weatherSpiderV3.wsgi文件,文件名自己按自己情况定义
import sys
#Expand Python classes path with your app's path
sys.path.insert(0, "E:/PythonWeatherServer")
from weatherSpiderV3 import app
#Put logging code (and imports) here ...
#Initialize WSGI app object
application = app
6.配置Virtual hosts
去掉“# Include conf/extra/httpd-vhosts.conf” 前的#号 如下:
# Virtual hosts
Include conf/extra/httpd-vhosts.conf
打开httpd-vhosts.conf文件,注释掉DocumentRoot "${SRVROOT}/htdocs" 如下:
<VirtualHost _default_:80>
#DocumentRoot "${SRVROOT}/htdocs"
#ServerName www.example.com:80
</VirtualHost>
添加一个
<VirtualHost *:2002>
ServerName localhost
#ServerAlias www.test.com
#ServerAdmin root@test.com
DocumentRoot "E:/PythonWeatherServer"
#ErrorLog "E:/PythonWeatherServer/error.log"
WSGIScriptAlias / E:/PythonWeatherServer/weatherSpiderV3.wsgi
#Alias /static F:/web/static
<Directory "E:/PythonWeatherServer">
#Options +ExecCGI
#AddHandler cgi-script .py
#Options -Indexes +FollowSymLinks
Require all granted
AllowOverride All
WSGIScriptReloading On
</Directory>
</VirtualHost>
按自己的实际情况进行配置“端口号、ServerName、DocumentRoot、WSGIScriptAlias、<Directory”等。
重启服务器即可。