django通过apache+mod_wsgi部署在windows上(精)

先交代一下环境:

Apache2.4

django1.11

python3.5

 一、在服务器上安装语言环境

    在服务器上安装的python,django的版本要与项目中的版本一样,

    1、安装python 下载地址:https://www.python.org/downloads/

    2、安装django 下载地址:https://pypi.org/project/Django/#history

    3、安装mod_wsgi 下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mod_wsgi

    注意:需要对应apache和python的版本进行下载,32位对应32位apache,64位对应64位apache

下载后将文件复制到python安装目录下的script目录下,在此目录下运行cmd,输入指令pip install xxxx.whl 进行安装(如有需要的模块,可以下载离线的whl)

    安装完毕后cmd输入

mod_wsgi-express module-config

成功后输出3条信息,留着有用

LoadFile "c:/users/administrator/appdata/local/programs/python/python37-32/python37.dll"

LoadModulewsgi_module "c:/users/administrator/appdata/local/programs/python/python37-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win32.pyd"

WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python37-32"

 

二、在服务器上安装Apache

下载apache(免安装版) 下载地址:http://httpd.apache.org/

 下载windows系统适配的apache版本,注意是基于x86还是x64的版本

将其解压到你想放的位置,我放在了d盘

在bin目录下运行cmd,输入指令start httpd或者双击httpd.exe即可启动服务器

开机自动启动并将apache加入系统服务(最好还是配置一下):

httpd -k install

启动服务:  httpd -k start

停止服务:     httpd -k stop

重启服务:     httpd -k restart

 

三、配置apache 

 配置文件在Apache24\conf\httpd.conf

需要修改的地方

ServerRoot "d:/"  

DocumentRoot "/httpd-2.2-x64/htdocs"  

<Directory "/httpd-2.2-x64/cgi-bin">  

ScriptAlias /cgi-bin/ "/httpd-2.2-x64/cgi-bin/"  

修改为 :

ServerRoot "d:/Apache24"  

DocumentRoot "d:/Apache24/htdocs"  

<Directory "d:/Apache24/cgi-bin">  

ScriptAlias /cgi-bin/ "d:/Apache24/cgi-bin/"  

 设置本地或者你要配置的域名和监听

ServerName localhost:80

 需要增加的地方:

加入之前mod_wsgi输出的信息

LoadFile "d:/python35/python35.dll"
LoadModule wsgi_module "d:/python35/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win_amd64.pyd"
WSGIPythonHome "d:/python35"

配置连接django的wsgi(根据你项目的路径):

#Django项目中wsgi.py的路径
WSGIScriptAlias / d:/eprbackend/eprbackend/wsgi.py

#Django项目的路径
WSGIPythonPath d:/eprbackend

#配置wsgi.py的访问权限
<Directory d:/eprbackend/eprbackend>
<Files wsgi.py>
Require all granted
</Files>
</Directory>

配置静态文件连接的路径问题(根据你项目中static的路径):

Alias /static/ d:/eprbackend/static/
<Directory d:/eprbackend/static/>
    #Order deny,allow
    #Allow from all
    Require all granted
</Directory>

 

四、配置django

在django项目中的settings中加入

STATIC_URL = '/static/'
STATICFILES_DIRS = (
    # 告诉django static的路径
    os.path.join(BASE_DIR, "static"),
)

并修改

DEBUG = False

ALLOWED_HOSTS = ['*']

 代表所有ip都可进行访问 

 

搞定!!!

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值