Skip to content
DevOps AI ToolKit
Newsletter
All prompts
AI for NGINX Difficulty: Advanced ClaudeChatGPTCursor

NGINX Canary & Blue-Green Routing Prompt

Design percentage-based canary and blue-green traffic routing in NGINX using split_clients and upstream weighting — with a sticky cohort, an instant rollback path, and a way to force yourself onto the canary for testing.

Target user
Engineers rolling out releases behind NGINX without a service mesh
Difficulty
Advanced
Tools
Claude, ChatGPT, Cursor

The prompt

You are a senior release engineer who ships canary and blue-green deployments through NGINX without a service mesh. You care about cohort stickiness, instant rollback, and being able to test the canary yourself before real traffic sees it.

I will provide:
- My two backend pools (stable and canary), as host:port lists: [PASTE UPSTREAMS]
- The routing strategy I want (percentage canary, or blue-green cutover): [DESCRIBE]
- The starting canary percentage and how I plan to ramp it: [e.g. 1% → 5% → 25% → 100%]
- Whether sessions must be sticky, and what stable key I can hash on (cookie, IP): [DESCRIBE]
- How I want to force MYSELF onto the canary for testing (header, cookie, source IP): [DESCRIBE]

Design the routing:

1. **split_clients cohort** — a `split_clients "${key}" $variant { N% canary; * stable; }` block. Explain why the key must be stable (so a user doesn't flip between variants) and what happens as I change the percentage.

2. **Upstreams** — define `upstream stable` and `upstream canary` (or a single upstream with `weight=` for the simplest case), and map `$variant` to the chosen `proxy_pass` target with a `map`.

3. **Override for testers** — a way to bypass the percentage split entirely (e.g. `X-Canary: 1` header or a cookie) so I can hit the canary deterministically, plus a way to pin known-good traffic to stable.

4. **Blue-green variant** — show the one-line change (a `map` default or a variable) that flips 100% of traffic between blue and green, and the reverse for rollback.

5. **Observability** — add the variant to the access log (`$variant` in `log_format`) and set a response header (`X-Served-Pool`) so I can confirm which pool served a request.

Output: (a) the full `http`-level `split_clients`/`map`/`upstream` config plus the `location` block, commented; (b) the exact edit-and-reload steps to ramp the percentage; (c) the single change that triggers rollback; (d) `curl` commands proving the header override and the pool header work. Apply only after `nginx -t` passes and reload.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Why this prompt works

The two ways teams break NGINX canaries are hashing on an unstable key (so users flip between old and new code mid-session) and building a rollback that requires editing several places at once. This prompt makes you name a stable hash key up front and demands a rollback that is a single value change plus a reload — the thing you actually want at 2am.

Forcing a tester override (X-Canary header or cookie) means you can validate the new pool deterministically before any percentage of real users reach it, instead of refreshing and hoping the hash lands you on the canary. Logging $variant and setting X-Served-Pool turns “is my canary getting traffic?” into a fact you can grep and curl, not a guess.

Because split_clients and the upstreams live at the http level, the design stays declarative: ramping is a percentage edit, cutover is a map default flip, and both are reversible under an nginx -t gate.

Related prompts

More NGINX prompts & error guides

Browse every NGINX prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.