1. 程式人生 > >flask Apache 部署

flask Apache 部署

module virt oca errors 顯示 all 執行 sting expr

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 [email protected]
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/

flask Apache 部署