环境:windows7 64bit
1、python版本3.6.5,32位
2、下载Apache,版本httpd-2.4.33-o102o-x86-vc14-r2,32位,vc14编译
3、下载mod_wsgi,版本mod_wsgi-4.6.4+ap24vc14-cp36-cp36m-win32.whl,32位,vc14编译,下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
注意,这些都是32位以及vc14编译
4、安装Apache
5、安装mod_wsgi
pip install mod_wsgi-4.6.4+ap24vc14-cp36-cp36m-win32.whl
mod_wsgi-express module-config
输出如下三行结果
把这三行内容复制到Apache的配置文件http.cnf下进行配置
6、建立flask工程flask_test,flask_test.py
1 import random 2 import time 3 4 app = Flask(__name__) 5 6 @app.route('/open') 7 def open(): 8 key = request.args.get('key') 9 time.sleep(5) 10 return key 11 12 if __name__ == '__main__': 13 app.run(host='0.0.0.0',port=5000,threaded=True)
test.py
import sys sys.path.insert(0, "c:/Users/dell/PycharmProjects/flask_test") from flask_test import app application = app
7、修改Apache配置文件http.cnf
Listen 5000 <VirtualHost *:5000 > ServerName example.com <Directory "c:UsersdellPycharmProjectsflask_control"> AllowOverride All Require all granted </Directory> WSGIScriptAlias / c:UsersdellPycharmProjectsflask_control est.py </VirtualHost>
8、启动Apache,使用管理员权限运行httpd.exe
9、测试访问成功