环境:
系统 win10
apache2.4 win64
mod_wsgi-4.7.1-cp38-cp38-win_amd64(根据具体python和系统版本下载)
python 3.8
django 2.2
mysql5.7
python3.8 和django2.2,mysql5.7 的部署其他文章有写,在此忽略
1、apache下载、安装与配置
1.1、下载地址:
https://www.apachelounge.com/download/
下载的是 httpd-2.4.46-win64-VS16.zip
1.2、默认根目录路径是c:
解压把内部Apache24目录拷贝到C盘
修改 C:\Apache24\conf\httpd.conf 监听8009端口
Listen 127.0.0.1:8009
1.3、C:\Apache24\bin>httpd.exe
浏览器测试:
http://127.0.0.1:8009
浏览器返回:
It works!
表示apache安装OK
2、mod_wsgi下载、安装与配置
2.1、下载
https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi
说明:
Mod_wsgi: a WSGI adapter module for the Apache HTTP Server 2.4.
Linked against the VC16 binaries from Apache Lounge and VC9 binaries from Apache House.
See Running mod_wsgi on Windows for version (in)compatibilities.
下载的是 mod_wsgi‑4.7.1‑cp38‑cp38‑win_amd64.whl
python38 window64位
2.2、安装
F:\apache_mod_wsgi_django2.2>pip install mod_wsgi-4.7.1-cp38-cp38-win_amd64.whl
Processing f:\softwares\special\apache_mod_wsgi_django2.2\mod_wsgi-4.7.1-cp38-cp38-win_amd64.whl
Installing collected packages: mod-wsgi
Successfully installed mod-wsgi-4.7.1
2.3、生成apache加载mod_wsgi的命令
C:\Python38\Scripts>mod_wsgi-express module-config
LoadFile "c:/python38/python38.dll"
LoadModule wsgi_module "c:/python38/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd"
WSGIPythonHome "c:/python38"
3、修改 C:\Apache24\conf\httpd.conf 添加
LoadFile "c:/python38/python38.dll"
LoadModule wsgi_module "c:/python38/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd"
WSGIPythonHome "c:/python38"
WSGIScriptAlias / D:/mysite/wsgi.py
WSGIPythonPath D:/mysite
<Directory D:/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
4、屏蔽apache默认的配置
#<Directory "${SRVROOT}/htdocs">
# Options Indexes FollowSymLinks
# AllowOverride None
# Require all granted
#</Directory>
5、重新启动httpd
C:\Apache24\bin>httpd.exe
6、通过浏览器访问http://127.0.0.1:8009
一切正常
7、django项目目录结构说明
d:/mysite
d:/mysite/wsgi.py
import sys
import os
import tempfile
p = os.path.abspath(os.path.dirname(__file__))
sys.path.insert(0, os.path.split(p)[0])
os.environ["DJANGO_SETTINGS_MODULE"] = "settings"
os.environ["PYTHON_EGG_CACHE"] = os.path.join(tempfile.gettempdir(),".python-eggs")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
d:/mysite/settings.py
d:/mysite/myapp/models.py
项目的根目录名称不要命名为platform
和python里面的platform库冲突,会报错,
可以查看apache下的错误日志