Win7下装Apache2.4运行Django3

1、下载并安装Apache2.4.53
apache官方不提供二进制版本,只提供源码。我们需要从第三方下载编译的二进制(.exe)版本。
打开apache官网的下载页面:

https://httpd.apache.org/download.cgi

在这里插入图片描述在这里插入图片描述如果你的电脑是64位的,在打开的下载页面选择64位的下载:
在这里插入图片描述将下载的Apache压缩包解压到D:盘,如Apache24文件夹,在命令提示符下,进入到该文件夹下的bin文件夹,运行

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

安装完成后,在命令行下运行:

mod_wsgi-express module-config

会输入三行文字,将这三行文字复制粘贴到Apache24\conf文件夹下的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替换成自己的项目名称即可

<VirtualHost *:80>
	# 域名
	ServerName roctest.com
	ServerAlias www.roctest.com

	#指定website的wsgi.py配置文件路径 
	WSGIScriptAlias / D:\django\roctest\roctest\wsgi.py

	# 指定访问和错误日志路径,这里的文件夹要提前建好
	ErrorLog  D:\django\roctest\log\error_log
	CustomLog D:\django\roctest\log\access_log common

	#指定项目路径  
	#WSGIPythonPath D:\django\roctest
	<Directory D:\django\roctest>
		<Files wsgi.py>
			Require all granted
		</Files>
	</Directory>
	 
	#项目静态文件地址, Django项目中静态文件的路径  
	Alias /static D:\django\roctest\static
	<Directory D:\django\roctest\static>
		AllowOverride None
		Options None
		Require all granted
	</Directory>
	 
	#项目media地址, 上传图片等文件夹的路径
	Alias /static D:\django\roctest\media
	<Directory D:\django\roctest\static\media>
		AllowOverride None
		Options None
		Require all granted
	</Directory>
</VirtualHost>

项目的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:\django\roctest')

application = get_wsgi_application()
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值