flask Apache 部署(值得参考)
1.下载Apache zip包解压,放在C盘根目录下,cmd命令 切换至 Apache24/bin目录下,输入命令httpd -k install安装,httpd -k uninstall 删除安装
C:\Apache24\bin>httpd -k install
Installing the 'Apache2.4' service
The 'Apache2.4' service is successfully installed.
Testing httpd.conf....
Errors reported here must be corrected before the service can be started.
说明安装成功,在浏览器输入 http://localhost 会显示It Works, 说明安装成功
2下载跟python对应版本的mod_wsgi.whl文件,pip install mod_msgi.whl (注意路径)
进入到python的Scripts路径中 cmd 输入 mod_wsgi-express module-config
PS C:\Users\user\AppData\Local\Programs\Python\Python36\Scripts> mod_wsgi-express module-config
LoadFile "c:/users/user/appdata/local/programs/python/python36/python36.dll"
LoadModule wsgi_module "c:/users/user/appdata/local/programs/python/python36/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win_amd64.pyd"
WSGIPythonHome "c:/users/user/appdata/local/programs/python/python36"
复制加粗的三句话,粘贴到Apache/conf 下的htppd.conf文件尾部
3创建一个wsgi.py 文件
写入
import sys, os
# 我的项目在'C:/Users/user/Desktop/flask_news下
#Expand Python classes path with your app's path
sys.path.insert(0, 'C:/Users/user/Desktop/flask_news')
from flask_news import app
#Put logging code (and imports) here ...
#Initialize WSGI app object
application = app
4 在Apache/conf 下的htppd.conf文件尾部加入
我的端口改为了8081
<VirtualHost *:8081>
ServerAdmin example@company.com
WSGIScriptAlias /app c:\mydir\wsgi.py
#对应wsgi.py的路径
<Directory c:\mydir>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
5.cmd(管理员) 切换都Apache bin目录下 执行 httpd -k uninstall, httpd -k install, net sart Apache2.4
6.浏览器输入 http://localhost:8081/app/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?