必要条件:
1、 python环境
2、服务器
3、mod_wsgi
下面是我的机子的环境:
python:python3.7.3 (64位)

apache服务器:
1:下载apache:下载
我是64位 win10系统:

2:解压文件并将解压出的“apache24”放到自己的目录(我这里是E:\softwore-install\apache):

E:\softwore-install\apache目录:
修改配置文件:Apache24\conf\httpd.conf :修改其中的如图所示处:

3:接下来测试一下服务器,看是否能正常运行:打开cmd。 切换到 Apache24\bin 执行httpd.exe,如果能正常运行就是:

可能会出现如下图的警告:AH00558: httpd.exe: Could
not reliably determine the server's fully qualified domain name, using
fe80::842:1c5:da2d:ba3a. Set the 'ServerName' directive globally to suppress
this message :这个不影响服务器运行。你可以修改 配置文件:Apache24\conf\httpd.conf
。指明你的ServerName。

4:打开服务器后: 打开浏览器:输入 localhost :可以看到:it work! 你就成功了。

二:接下来把 mod_wsgi 添加到apache 服务器中:
1:下载 mod_wsgi: 地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
这里 一定注意版本对应!!!
我这里用的是:mod_wsgi-4.6.5+ap24vc15-cp37-cp37m-win_amd64.whl


2:将提取出来的文件放到 Apache24\modules
中:(我这里重命名了)

3:修改配置文件
Apache24\conf\httpd.conf :新增:
LoadModule wsgi_modulemodules/mod_wsgi.pyd

4:到了激动人心的时刻了。重启一下apache服务器,看是否有报错。如果没有,说明成功了。
三:接下来就是 部署Flask :
1:首先写一个最简单的Flask 应用,并进行发布:这里在跟 apache24 同一目录下也就是 C盘根目录下:创建mydir目录。在目录中写两个文件:hello.py 和myapp.wsgi:

hello.py:
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World!终于成功了。我擦"
if __name__ == '__main__':
app.run()
myapp.wsgi:
import sys
sys.path.insert(0, 'c:\\mydir')
from hello import app as application
这里的 application 必须是这个。服务器只看这个。
2:修改配置文件:Apache24\conf\httpd.conf 新增几行:
<VirtualHost *:80>
WSGIScriptAlias /myapp c:\mydir\myapp.wsgi
<Directory c:\mydir>
Require all granted
</Directory>
</VirtualHost>
3:到此。所有配置已 填写完毕。
启动服务器。输入 http://localhost/myapp 即可看到自定义的页面。

网友评论