flask框架部署(Windows+Aapche+mod_wsgi)

参考

[1]Windows下Flask+Apache+mod_wsgi部署Flask项目
阅读此文,部署环境添加模块时出错。解决办法,参考[2]
[2]Apache 加载mod_wsgi.so出错,什么原因?

详细步骤

Step1:下载Apache并解压

地址:https://www.apachelounge.com/download/VC10/

Step2:修改配置文件(不在C盘解压时需要)

ServerRoot
ServerName
DocumentRoot
flask框架部署(Windows+Aapche+mod_wsgi)_第1张图片

flask框架部署(Windows+Aapche+mod_wsgi)_第2张图片
在httpd.conf文件中找到


    AllowOverride none
   Require all denied

改为:


    #Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order deny,allow
    Allow from all

测试

flask框架部署(Windows+Aapche+mod_wsgi)_第3张图片
flask框架部署(Windows+Aapche+mod_wsgi)_第4张图片

Step3:把 mod_wsgi 添加到apache 服务器中

mod_wsgi下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
解压(使用pip安装),将mod_wsgi.cp37-win_amd64.pyd复制到Apache的modules中
flask框架部署(Windows+Aapche+mod_wsgi)_第5张图片
flask框架部署(Windows+Aapche+mod_wsgi)_第6张图片

Step4:再修改配置文件

在Apache24\conf\httpd.conf 新增

flask框架部署(Windows+Aapche+mod_wsgi)_第7张图片

mod_wsgi-express module-config

flask框架部署(Windows+Aapche+mod_wsgi)_第8张图片

LoadFile "d:/software/anaconda/dir/python37.dll"
LoadModule wsgi_module "d:/software/anaconda/dir/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd"
WSGIPythonHome "d:/software/anaconda/dir"

再测试

flask框架部署(Windows+Aapche+mod_wsgi)_第9张图片

部署flask

flask框架部署(Windows+Aapche+mod_wsgi)_第10张图片

(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

在配置文件中新增几行代码


     WSGIScriptAlias /myapp c:\mydir\myapp.wsgi
     
         Require all granted
     


flask框架部署(Windows+Aapche+mod_wsgi)_第11张图片

测试结果

flask框架部署(Windows+Aapche+mod_wsgi)_第12张图片

你可能感兴趣的:(flask框架笔记)