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

Tune NGINX proxy_cache for Hit Ratio Prompt

Design and tune NGINX proxy_cache to raise hit ratio and offload an upstream while respecting cache-control correctness, with the right cache key, zones, stale-serving, and purge strategy.

Target user
Platform engineers caching dynamic and static responses at NGINX
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a senior platform engineer who tunes NGINX content caching. I want to raise my proxy_cache hit ratio and offload the upstream without serving wrong content.

I will provide:
- My current `proxy_cache_path`, `proxy_cache`, and related directives (or none if starting fresh)
- The upstream's Cache-Control / Set-Cookie / Vary headers for the responses I want to cache
- Which paths are cacheable, which are per-user, and the typical object size + working-set size
- Current `$upstream_cache_status` distribution from access_log if available

Your job:

1. **Decide what's cacheable** — separate truly cacheable responses from per-user ones, and flag Set-Cookie or `Vary: Cookie` responses that silently disable caching.
2. **Design the cache key** — build `proxy_cache_key` deliberately (scheme/host/uri plus only the query/headers that matter) to avoid fragmenting the cache or mixing users.
3. **Size zones & storage** — set `proxy_cache_path` keys_zone, `max_size`, `inactive`, and levels for the working set, and explain the memory vs disk tradeoff.
4. **Set validity** — use `proxy_cache_valid` per status code, honor or override upstream Cache-Control, and add `proxy_ignore_headers` only where justified.
5. **Resilience** — enable `proxy_cache_use_stale` and `proxy_cache_background_update` + `proxy_cache_lock` to serve stale during upstream errors and avoid thundering herds.
6. **Observe & purge** — add `$upstream_cache_status` to the log format and define a purge/bypass mechanism (`proxy_cache_bypass`/`X-Accel`).
7. **Verify** — give curl + log commands showing HIT/MISS/STALE and a measured before/after hit ratio.

Output as: (a) cache config, (b) cache-key + validity rationale, (c) purge strategy, (d) verification.

Run this prompt with AI

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

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.