How best do I host a Django web app on the same server but for two separate domains?
I have a Django web app, deployed with Apache+mod_wsgi, that I'd like to access through two separate domains (e.g. wwww.mydomain.com and www.otherdomain.com). Both domains share the same database and user accounts, but have domain-specific functionality (mostly aesthetic, showing a different template, graphics, some extra tools, etc).
Each domain also has its own SSL certificate. It's also possible for users to be bounced between domains (e.g. they start out on mydomain.com then they "enable" functionality that takes them to otherdomain.com).
At first I thought all I had to do was append the domains to the ServerAlias directive in my Apache conf file. e.g. ServerAlias *mydomain.com *otherdomain.com
. However, I'm running into a few problems.
If I'm reading this correctly, a single Apache section can only support a certificate for one domain (excluding wildcard certs for subdomains), so in order to support HTTPS on both domains I would need to duplicate my , swapping in the different cert info for the second domain.
In order to properly track cookies, I need to set
SESSION_COOKIE_DOMAIN
andCSRF_COOKIE_DOMAIN
to the domain being used. However, this can only be done once per settings.py, so outlined here, I need to create duplicate settings.py files (e.g. settings_mydomain.py and settings_otherdomain.py) as well as duplicate django.wsgi files, each using the appropriate settings module.With the default setup, if a user gets bounced from one domain to the other, they'll lose all their cookies, causing them to be logged out if they were logged in. I'm not sure how best to work around this. Since the user is being redirected by a Django view, at first I was thinking I could copy over the cookies, swapping out the old domain for the new one. Another thought is to copy the cookies to a database table, indexed with a one-use lookup hash (e.g. the same way Django does registration confirmations), and include this hash in the redirect, which the app would then use to lookup the cookies and set them in the client. Would either of these work?
Are there any better solutions to these 3 problems? Are there any other issues or problems I've overlooked?