apache配置多个django服务器

根据我之前的博客先实现一个apache运行一个django服务器成功后再开始搭建多个django服务器程序。

博客链接

1 配置apache

1.1 找到相对路径:Apache24\conf\下的配置文件httpd.conf

找到如下内容:

# Virtual hosts
# Include conf/extra/httpd-vhosts.conf

修改为:

#配置多个服务器程序
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

在配置文件的尾部加入如下内容:

#添加mod_wsgi,这三行是安装mod_wsgi命令行中显示出来的
LoadFile "c:/users/administrator/appdata/local/programs/python/python35-32/python35.dll"
LoadModule wsgi_module "c:/users/administrator/appdata/local/programs/python/python35-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp35-win32.pyd"
WSGIPythonHome "c:/users/administrator/appdata/local/programs/python/python35-32"
 
#使用多个端口
Listen 80
Listen 8800

1.2 配置多个服务器的具体内容:

找到相对路径:Apache24\conf\extra\下的httpd-vhosts.conf

在该文件尾部加入如下内容:

#配置product1服务器
<VirtualHost 0.0.0.0:80>


#设置wsgi路径

    WSGIScriptAlias / c:/product1/product1/wsgi.py

    <Directory c:/product1/product1>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>

#设置静态文件路径(根据自己需要调整)

    Alias /static c:/product1/static
    <Directory c:/product1/static>  
        AllowOverride None  
        Options None  
        Require all granted  
    </Directory> 

#设置项目的根目录

    DocumentRoot "c:/product1"

    <Directory "c:/product1">

        Options Indexes FollowSymLinks

        AllowOverride None

        Require all granted

    </Directory>

</virtualHost>

<VirtualHost 0.0.0.0:8800>


#设置wsgi路径

    WSGIScriptAlias / c:/product2/product2/wsgi.py

    <Directory c:/product2/product2/>
    <Files wsgi.py>
        Require all granted
    </Files>
    </Directory>

#设置静态文件路径(根据自己需求配置,可配置多个静态文件路径)

    Alias /static c:/product2/static
    <Directory c:/product2/static>  
        AllowOverride None  
        Options None  
        Require all granted  
    </Directory> 

#设置项目的根目录

    DocumentRoot "c:/product2/"

    <Directory "c:/product2/">

        Options Indexes FollowSymLinks

        AllowOverride None

        Require all granted

    </Directory>

</virtualHost>

2 配置django服务器中的wsgi.py

2.1 各个服务器wsgi.py中加入如下内容:

import os

import sys 

root_path= os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

sys.path.insert(0,root_path)

3. 最后启动httpd.exe即可。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值