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/

posted @ 2022-03-31 16:46  心雨星空  阅读(585)  评论(0编辑  收藏  举报