Sunday, 15 July 2012

apache - Multiple Sites in Django -



apache - Multiple Sites in Django -

does know how add together multiple domains django. i've tried next guides here multiple sites under single django project no luck.

my configuration looks

settings

/opt/django/project/settings.py

/opt/django/project/domain1_settings.py

url

/opt/django/project/urls.py

/opt/django/project/domain1_urls.py

wsgi

/opt/django/project/domain1/domain1.wsgi

apache

/etc/httpd/conf.d/django.conf

<virtualhost * > servername domain1.co.uk serveralias www.domain1.co.uk direct.domain1.co.uk wsgidaemonprocess domain1 processes=5 python-path=/usr/bin/python threads=1 wsgiscriptalias / /opt/django/project/domain1/domain1.wsgi errorlog logs/domain1-error.log customlog logs/domain1-access.log mutual </virtualhost>

when restart apache see no errors when go site sent (non django) domain configured within main httpd.conf.

thanks,

this reply makes assumption want have 2 domain names each running separate django projects, beingness hosted same apache server. if isn't case, please refine question!

to start you'll need 2 virtualhost entries in apache conf (let's phone call sites domain1.co.uk , domain2.co.uk)

# virtual hosts setup namevirtualhost * <virtualhost *> servername domain1.co.uk wsgidaemonprocess application_name processes=5 python-path=/opt/django/project/domain1:/home/username/webapps/application_name/lib/python2.6 threads=1 wsgiscriptalias / /opt/django/project/domain1/domain1.wsgi </virtualhost> <virtualhost *> servername domain2.co.uk wsgidaemonprocess application_name_www processes=5 python-path=/opt/django/project/domain2:/home/username/webapps/application_name/lib/python2.6 threads=1 wsgiscriptalias / /opt/django/project/domain2/domain2.wsgi </virtualhost>

you'll need 2 wsgi files (pointed 2 in conf above)

/opt/django/project/domain1/domain1.wsgi /opt/django/project/domain1/domain2.wsgi

and like

import os import sys django.core.handlers.wsgi import wsgihandler os.environ['django_settings_module'] = 'project.settings' # or project.domain1_settings application = wsgihandler()

onto settings.py create sure both settings files have difference site_id = 1 or site_id = 2 , point right urls.py

root_urlconf = 'urls'

or

root_urlconf = 'domain1_urls'

much of question has been sourced personal experience , blog post. project directories , domain names seem little confusing, i've done best fit them right places here, need adjust own purposes.

additional

if have 2 sites running same server, have careful maintain consistency on project directories, static file directories , settings files etc. question settings files /opt/django/project/settings.py , /opt/django/project/domain1_settings.py quite confusing seems have 1 project directory (/opt/django/project). recommend stronger separation; describe above, maybe setting projects (domain1 , domain2) in directories

/opt/django/project/domain1/ /opt/django/project/domain2/

with corresponding settings files

/opt/django/project/domain1/settings.py /opt/django/project/domain2/settings.py

etc. should create easier spot going wrong where.

django apache virtualhost

No comments:

Post a Comment