Danil Danil - 1 month ago 7
Apache Configuration Question

How should I implement corporate accounts on the web-site?

I have already ready WEBsite with user authentication.
I need to implement corporate accounts functional, so that users of this account can go to the link corporate_account_name.main_domain.com and saw the same site as in main_domain.com only this version especially for them.

How to do it and where to dig? (or at least a list of technologies, frameworks):


  1. One code for all subdomains?

  2. Create separate database for each subdomain? At the same time you need to access data from main_domain to all subdomains and vice versa (subdomain -> main_domain).

  3. It is likely that the code may need to update the long migration of the database data. It is necessary that in this case all the subdomains not froze until the updated one of the bases.

  4. The server on apache. This restart apache every time you create a business account is not possible.

  5. Corporate accounts creates on the web interface main_domain.com (automatically), like a standard user registration. Do not manually!

  6. It is desirable for django.


Answer

There is django-tenant-schemas package, which seems totally fit your needs.

A brief description of how it works (from docs):

Tenants are identified via their host name (i.e tenant.domain.com). This information is stored on a table on the public schema. Whenever a request is made, the host name is used to match a tenant in the database. If there’s a match, the search path is updated to use this tenant’s schema. So from now on all queries will take place at the tenant’s schema. For example, suppose you have a tenant customer at customer.example.com. Any request incoming at customer.example.com will automatically use customer‘s schema and make the tenant available at the request. If no tenant is found, a 404 error is raised. This also means you should have a tenant for your main domain, typically using the public schema.

Comments