Windows 在apache中使用mod_wsgi部署flask
下载mod_wsgi Python的插件,选择 mod_wsgi-4.5.24+ap24vc14-cp37-cp37m-win_amd64.whl,
1
2
3http://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
https://download.lfd.uci.edu/pythonlibs/h2ufg7oq/mod_wsgi-4.5.24+ap24vc14-cp37-cp37m-win_amd64.whl在下载时要选择相应的版本,否则Apache启动时会有问题
Apache24 VC是14
Python3.7
64位把下载的.whl文件复制到python37/Scripts下,命令行执行
1
pip install "mod_wsgi-4.5.24+ap24vc14-cp37-cp37m-win_amd64.whl"
安装成功,python37/Scripts下命令行执行
1
mod_wsgi-express module-config
输出如下三行结果
1
2
3LoadFile "d:/ide/python37/python37.dll"
LoadModule wsgi_module "d:/ide/python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "d:/ide/python37"把这三行内容复制到apache的conf路径下http.cnf文件下进行配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22#############################
# 配置python下wsgi
LoadFile "D:/IDE/Python37/python37.dll"
LoadModule wsgi_module "D:/IDE/Python37/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "D:/IDE/Python37"
# 监听端口
Listen 81
# python项目的根目录和wsgi路径
<VirtualHost *:81>
DocumentRoot "D:/IDE/WorkSpace/Python/flask_test/"
ServerName localhost:81
WSGIScriptAlias / "D:/IDE/WorkSpace/Python/flask_test/flask_wsgi.py"
</VirtualHost>
# 虚拟目录的权限配置
<Directory "D:/IDE/WorkSpace/Python/flask_test/">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
##############################注释http.cnf中的mod_wsgi.so(如果有)
1
#LoadModule wsgi_module modules/mod_wsgi.so
安装apache服务器,进入D:\IDE\Apache24\bin目录,执行如下命令安装
1
2httpd.exe -k install
# httpd.exe -k uninstall执行如下命令检查
1
D:\IDE\Apache24\bin>httpd.exe -n "Apache2.4" -t
以服务启动