这跟我做的一样。我借来的
http://michal.karzynski.pl/blog/2010/10/19/run-multiple-websites-one-django-project/
基本上,您将在每个域的http.conf文件上创建一个virtualhost条目。
# Virtual hosts setup
NameVirtualHost *
<VirtualHost *>
ServerName example1.com
WSGIDaemonProcess APPLICATION_NAME processes=5 python-path=/home/USERNAME/webapps/APPLICATION_NAME:/home/USERNAME/webapps/APPLICATION_NAME/lib/python2.6 threads=1
WSGIScriptAlias / /home/USERNAME/webapps/APPLICATION_NAME/domain1.wsgi
</VirtualHost>
<VirtualHost *>
ServerName example2.com
WSGIDaemonProcess APPLICATION_NAME_www processes=5 python-path=/home/USERNAME/webapps/APPLICATION_NAME:/home/USERNAME/webapps/APPLICATION_NAME/lib/python2.6 threads=1
WSGIScriptAlias / /home/USERNAME/webapps/APPLICATION_NAME/domain2.wsgi
</VirtualHost>
然后,您需要为每个域创建两个不同的wsgi文件,并将它们放在保存项目的目录中。wsgiscriptaalias是wsgi文件的路径,因此请确保它们是相同的…
示例wsgi文件:
import os
import sys
from django.core.handlers.wsgi import WSGIHandler
os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECT_NAME.domain1_settings' # or PROJECT_NAME.domain2_settings
application = WSGIHandler()
然后您需要创建两个额外的设置文件…所以你会拥有
settings.py
domain1_settings.py
domain2_settings.py
域1_settings.py和域2_settings.py将导入settings.py:
domain1_settings.py示例:
from settings import *
SITE_ID = 1
ROOT_URLCONF = 'domain1_urls'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
# other apps specific to this domain
)
最后,您需要创建两个独立的URL文件。
域1_urls.py和域2_urls.py
domain1_urls.py将是站点_id 1的默认值,domain2_urls.py将是站点_id 2的默认值。