1、下载并安装Apache2.4.53
apache官方不提供二进制版本,只提供源码。我们需要从第三方下载编译的二进制(.exe)版本。
打开apache官网的下载页面:
https://httpd.apache.org/download.cgi
如果你的电脑是64位的,在打开的下载页面选择64位的下载:
将下载的Apache压缩包解压到D:盘,如Apache24文件夹,在命令提示符下,进入到该文件夹,运行
httpd -k install
此命令会将httpd作为windows系统的服务启动,每次开机会自动启动httpd
2、下载mod_wsgi
在这里下载mod_wsgi模块
我的机器是64位,Python版本是3.8
下载后复制到python的script文件夹
在命令行下,进入到该文件夹,运行
pip3 install mod_wsgi-4.9.1-cp38-win_amd64.whl
会输入三行文字,将这三行文字复制粘贴到Apache24conf文件夹下的httpd.conf的文件末尾
LoadFile "c:/program files/python38/python38.dll" LoadModule wsgi_module "c:/program files/python38/lib/site-packages/mod_wsgi/server/mod_wsgi.cp38-win_amd64.pyd" WSGIPythonHome "c:/program files/python38"
把下面一行也加入到httpd.conf文件:
Include conf/sites/*.conf
在Apache24/conf文件夹下新建一个sites文件夹,在里面新建一个任意文件名的.conf文件,如:mysite.conf
3、配置Django项目
mysite.conf文件内容,其中的rocsite替换成自己的项目名称即可
# 域名 ServerName roctest.com ServerAlias www.roctest.com #指定website的wsgi.py配置文件路径 WSGIScriptAlias / D:djangoroctestroctestwsgi.py # 指定访问和错误日志路径,这里的文件夹要提前建好 ErrorLog D:djangoroctestlogerror_log CustomLog D:djangoroctestlogaccess_log common #指定项目路径 #WSGIPythonPath D:djangoroctest #项目静态文件地址, Django项目中静态文件的路径 Alias /static D:djangorocteststatic Require all granted AllowOverride None Options None Require all granted #项目media地址, 上传图片等文件夹的路径 Alias /static D:djangoroctestmediaAllowOverride None Options None Require all granted
项目的wsgi.py文件内容:
"""
WSGI config for roctest project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os, sys
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'roctest.settings')
#这一句必须加上,还有上面的import里也要有sys
sys.path.append(r'd:djangoroctest')
application = get_wsgi_application()



