Apache2.4 部署多个Django 本机不一样端口

先修改 apache 配置 conf/httpd.conf  开启虚拟功能
  LoadModule wsgi_module modules/mod_wsgi.so
  Include conf/extra/httpd-vhosts.conf  
这两行没有就添加上,有就去掉注释 #,注意第二行可能位置不同
Listen 4000
Listen 4001
再写上多个监听端口
而后去修改 httpd-vhosts.conf   下面是监听两个端口的django项目配置apache

<VirtualHost *:4000>  
    ServerName localhost:4000  
    WSGIScriptAlias / E:/xxx/wsgi.py  
    <Directory E:/xxx>   
        <Files wsgi.py>    
            Require all granted    
        </Files>    
    </Directory>   
    
    Alias /static E:/xxx/static
    <Directory E:/xxx/static>   
        Require all granted    
    </Directory>     
 
    DocumentRoot "E:/xxx"  
    <Directory "E:/xxx">  
        Options Indexes FollowSymLinks  
        AllowOverride None  
        Require all granted  
    </Directory>  
</virtualHost>  django

<VirtualHost *:4001>  
    ServerName localhost:4001  
    WSGIScriptAlias / E:/xxx/wsgi.py  
    <Directory E:/xxx>   
        <Files wsgi.py>    
            Require all granted    
        </Files>    
    </Directory>   
    
    Alias /static E:/xxx/static
    <Directory E:/xxx/static>   
        Require all granted    
    </Directory>     
 
    DocumentRoot "E:/xxx"  
    <Directory "E:/xxx">  
        Options Indexes FollowSymLinks  
        AllowOverride None  
        Require all granted  
    </Directory>  
</virtualHost>app

最后修改每一个django项目的wsgi.py,要否则访问会出错ide

import os
import sysui

# 要放在最前面
sys.path.append('E:/xxx/')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "yyy.settings")this

# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()server

# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)ip

相关文章
相关标签/搜索