Backend & Cloud Engineer Guide: Multi-Domain & Multi-Tenant SaaS Architecture with the Django Sites Framework, Nginx & Cloud Run

When a single backend platform serves multiple branded domains or regional country portals (e.g., `aldianfazrihady.com`, `aldianapps.com`, or custom white-label enterprise domains), running separate database clusters and duplicate container fleets wastes cloud budget. As a Senior Backend Engineer and Cloud Engineer, I use the Django Sites framework (`django.contrib.sites`) paired with dynamic host-header resolution on Google Cloud Run and Nginx to serve multiple domains from a unified codebase.

1. Dynamic Per-Request `Site` Resolution Middleware vs. Static `SITE_ID`

Instead of hardcoding `SITE_ID = 1` in `settings.py` and spinning up separate gunicorn processes per domain, resolve the active `Site` dynamically from the validated `Host` header (cached in process memory via `SITE_CACHE`):

from django.contrib.sites.models import Site
from django.http import HttpRequest

def get_current_tenant_site(request: HttpRequest) -> Site:
    """
    Resolves and caches the Django Site record from the validated HTTP Host header.
    """
    host = request.get_host().split(":")[0].lower()
    return Site.objects.get_current(request)

2. Strict `ALLOWED_HOSTS`, `CSRF_TRUSTED_ORIGINS` & Canonical SEO Isolation

3. Related Backend & Cloud Engineering Guides


⚡ Hire Aldian Fazrihady — Senior Cloud, GCP, Backend, AI Application & Full Stack Engineer

Need production cloud architecture, GCP/AWS infrastructure, high-throughput backend systems, AI agents, or full stack web engineering? Book a 1-Day Programming Sprint for $100 USD (International Card / Apple Pay) or Rp 1,000,000 (Indonesian QRIS / Bank Virtual Account), or hire directly on Upwork:

Book $100 / Rp 1M 1-Day Sprint → Hire on Upwork (100% Job Success) →


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs