先修改 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