环境: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.+ap24vc14-cp36-cp36m-win32.whl
mod_wsgi-express module-config
输出如下三行结果
把这三行内容复制到Apache的配置文件http.cnf下进行配置
6、建立flask工程flask_test,flask_test.py
import random
import time app = Flask(__name__) @app.route('/open')
def open():
key = request.args.get('key')
time.sleep(5)
return key if __name__ == '__main__':
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:\Users\dell\PycharmProjects\flask_control">
AllowOverride All
Require all granted
</Directory>
WSGIScriptAlias / c:\Users\dell\PycharmProjects\flask_control\test.py
</VirtualHost>
8、启动Apache,使用管理员权限运行httpd.exe
9、测试访问成功