Apache+modwsgi+django的配置

本文详细介绍如何将Django项目部署到Apache服务器上,包括安装配置mod_wsgi模块、设置httpd.conf文件、创建django.wsgi文件等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我的Django项目:viewPractice

①:下载modwsgi,将解压后的mod_wsgi.so放到apache的modules下

②:在apache的conf下的httpd.conf中加入下面语句:

   LoadModule wsgi_module modules/mod_wsgi.so

   WSGIScriptAlias / "D:/django_worksapce/viewPractice/viewPractice/django.wsgi"

注意:这里的路径要用UNIX风格的,即权为'/'

 ③:在你的django项目中settings.py所在目录下建立django.wsgi文件,这其实是一个python文件,内容如下:

    

<span style="font-size:18px;">import os
import sys
import django.core.handlers.wsgi
sys.path.append(r'D:\django_worksapce\viewPractice')#这里面是此文件所在文件夹的父文件夹                                                     #位置
os.environ['DJANGO_SETTINGS_MODULE'] = 'viewPractice.settings'#这里是改成你的setting即可
application = django.core.handlers.wsgi.WSGIHandler()</span>
 ④:在回到httpd.conf,找到这一代码块的位置,做修改如下加入,即将默认的APache的DocumentRoot改成你的项目所在的位置:

       

<span style="font-size:18px;">#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "D:\django_worksapce\viewPractice">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
   # Options Indexes FollowSymLinks

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
   # AllowOverride None

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory></span>

注意:.每改一次httpd.conf,重启apache才会有效。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值