慣性聚合 高效追讀感興趣之博客、新聞、科技資訊
閱原文 以慣性聚合開啟

推薦訂閱源

博客园 - 司徒正美
V
V2EX
T
Tailwind CSS Blog
有赞技术团队
有赞技术团队
aimingoo的专栏
aimingoo的专栏
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
Blog — PlanetScale
Blog — PlanetScale
A
About on SuperTechFans
月光博客
月光博客
T
The Blog of Author Tim Ferriss
宝玉的分享
宝玉的分享
Martin Fowler
Martin Fowler
博客园 - 聂微东
The GitHub Blog
The GitHub Blog
V
Visual Studio Blog
WordPress大学
WordPress大学
酷 壳 – CoolShell
酷 壳 – CoolShell
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
月租三十元之租户式SaaS:通配符SSL + Nginx虚拟主机生成器 + Flask路由
guardlabs_te · 2026-05-24 · via DEV Community

guardlabs_team

月费三十元之多元租户SaaS:其实架构

每“构建SaaS”之教程,未及首用户注册,已揽Kubernetes、托管Postgres及三云服务。尔无须此。此乃多元租户之设,于月费三十元之VPS,可运五十余租户于子域。

所求之要

白标合作之程。每伴得市肆于partner-{slug}.guardlabs.online與我等目錄相關,其推薦ID已嵌入其中。新夥伴→付費webhook觸發後自動配置。

第一階段(0-50租戶):通配符SSL+nginx+Flask

通配符SSL通過Let's Encrypt—一個證書覆蓋*.guardlabs.online:

certbot certonly --manual --preferred-challenges dns \
  -d "*.guardlabs.online" -d "guardlabs.online"

全屏顯示模式 退出全屏模式

DNS-01之挑战——添 TXT 记录于汝DNS提供者,certbot验之。

Nginx 服务器区块由路$host

server {
    listen 443 ssl;
    server_name ~^partner-(?<partner_slug>.+)\.guardlabs\.online$;
    ssl_certificate     /etc/letsencrypt/live/guardlabs.online/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/guardlabs.online/privkey.pem;

    location / {
        proxy_pass http://127.0.0.1:8090;
        proxy_set_header Host $host;
        proxy_set_header X-Partner-Slug $partner_slug;
    }
}

入全景模式 出全屏模式

Flask读其首部,一切皆归于此伴。

@app.before_request
def load_partner():
    slug = request.headers.get("X-Partner-Slug")
    if slug:
        g.partner = db.execute(
            "SELECT * FROM partners WHERE slug=?", (slug,)
        ).fetchone()
        if not g.partner:
            abort(404)

@app.route("/")
def storefront():
    products = get_catalog()  # global catalog
    return render_template("store.html",
        products=products,
        ref_id=g.partner["ref_id"],  # injected into every buy link
        partner_brand=g.partner["brand_name"])

入全景模式 出全屏模式

通过webhook进行配置 — 当Whop发送"新订阅"时:

@app.route("/webhook/whop", methods=["POST"])
def whop_webhook():
    event = verify_and_parse(request)
    if event["type"] == "subscription.created":
        slug = slugify(event["user"]["username"])
        # 1. DB row
        db.execute("INSERT INTO partners (slug, ref_id, ...) VALUES (...)")
        # 2. nginx — no per-partner config needed! Regex server_name catches it.
        # 3. Done. partner-{slug}.guardlabs.online works immediately.
    return "", 200

进入全屏模式 退出全屏模式

此乃要诀:正则表达式server_name意味着每家伙伴无需新增nginx配置。通配符SSL意味着无需新增证书。数据库行记录乃唯一写入操作。

容量:一VPS,单体Flask,SQLite。~50伙伴,每十人同用,则五百同用。三十美元一月之Hetzner CCX,不费吹灰之力可担此任。

第二阶段(五十至二百租户):每租户一SQLite

自共用DB迁至/data/partners/{partner_id}/store.db。Flask由X-Partner-Slug切换连接。约十六时重构。SQLite每文件容十万行无碍;二百伙伴×十万,计二百万行,亦无难事。

第三阶段(二百至五百以上):每租户一 PostgreSQL 模式

于此迁移。一 PostgreSQL,每伙伴一模式。四十时辰。 于此 或许欲 Kubernetes。未之前。

其旨

吾为此事,约八时辰而成。十二个月之总基建预算,未及五千美元。所谓"汝需微服务且管理一切"之建议,乃针对有财资与平台团队之公司。独行创业者:nginx正则+通配符SSL+Flask。before_request钩引君至五十租户。

试之

其助成之盟也:七日试用以无,不索卡,月贰拾玖。guardlabs.online/partner。而此机器人之始,乃幻影纸交易者(三百八十四交易,五十七胜率,公开)。

尔之“过度设计”之说何在?何时始用 Kubernetes 而非所需?


代码与全启日志公开。吾将随其后.


📥 免费章节——二十无预算增长之术

此启动日志运行于攻略之上。若欲得实策——谷歌生态之巧术、借势趋时、HARO权威之弈——取蓝图之两无价篇无PDF之障,无需登录:浏览器即开。真数真码,无浮华。

guardlabs.online( guardlabs 在线)/free-pdf