赞
踩
pip install mod-wsgi
安装的时候如果提示打不开‘apr_perms_set.h’文件,就去github上面下载apr的源码,然后把里面的这个文件放入apache\include下面即可
安装好之后,获取module配置
- C:\Users\Administrator>mod_wsgi-express module-config
- LoadFile "D:/software/Python310/python310.dll"
- LoadModule wsgi_module "D:/software/Python310/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
- WSGIPythonHome "D:/software/Python310"
- C:\Users\Administrator>
然后将mod_wsgi配置到apache
- ....
- #LoadModule watchdog_module modules/mod_watchdog.so
- #LoadModule xml2enc_module modules/mod_xml2enc.so
-
- LoadFile "D:/software/Python310/python310.dll"
- LoadModule wsgi_module "D:/software/Python310/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
- WSGIPythonHome "D:/software/Python310"
-
- <IfModule unixd_module>
- ...
为了不对apache内的原配置有影响,我们使用VirtualHost进行独立配置,而不是去修改apache的配置,这样如果以后我们还想再增加配置一个django项目就很方便了。
找到apache\conf下的httpd.conf
- ...
- Define SRVROOT "D:\software\BtSoft\BtSoft\apache"
- #定义flask项目路径(这并不是必须的,只是方便后面的使用)
- Define FLASKROOT "D:\software\JetBrains\project\flaskApp"
- ServerRoot "${SRVROOT}"
- ...
- Listen 80
- #新增监听81端口,这就是我们的flask网站端口
- Listen 81
找到apache\conf下的httpd.conf
- ...
- # Virtual hosts
- Include conf/extra/httpd-vhosts.conf
- ...
找到apache\conf\extra\httpd-vhosts.conf
- #跟上面监听的端口一致
- <VirtualHost *:81>
- ServerAdmin webmaster@dummy-host2.example.com
- #指定网站根目录
- DocumentRoot "${FLASKROOT}"
- #指定网站用localhost:81来访问
- ServerName localhost:81
- #这条命令就是指定对 localhost:81/.. 的访问都转由${FLASKROOT}/flaskApp.wsgi来处理
- WSGIScriptAlias / "${FLASKROOT}/flaskApp.wsgi"
- ErrorLog "logs/dummy-host2.example.com-error.log"
- CustomLog "logs/dummy-host2.example.com-access.log" common
- #指定目录下的文件都可访问
- <Directory "${FLASKROOT}">
- AllowOverride None
- Require all granted
- </Directory>
- </VirtualHost>
- import sys
- #将项目路径加入到python搜索目录中,否下面的test_flask_sqlalchemy模块是找不到的
- sys.path.insert(0, 'D:\\software\\JetBrains\\project\\flaskApp')
- #application名字是不能变的,因为mod_wsgi只认这个名字
- from test_flask_sqlalchemy import app as application
全部配置完成之后重启apache,打开浏览器访问 http://localhost:81/就能看到想要的效果。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。