The Complete Production SOP: How to Deploy and Run Production Nginx Hardener & Proxy in Autonomous AI Agents
Harden Nginx reverse proxies with TLS 1.3 and Cloudflare real IP using autonomous agent rules in Codex, Claude Code, and Cursor.
Technical Overview & Architectural Context
Autonomous coding agents frequently generate vulnerable Nginx configurations when prompted for reverse proxies. Unconstrained models tend to suggest deprecated SSL ciphers (TLSv1.0/1.1), omit buffer overflow protections (`client_body_buffer_size`), fail to configure `real_ip_header` against spoofed `X-Forwarded-For` headers, and configure rate limiting inside invalid contexts (`server` blocks instead of `http`). The Production Nginx Hardener & Proxy skill enforces deterministic constraints on autonomous agents across Codex, Claude Code, Cursor, and Windsurf. It injects hardened baseline templates that mandate TLS 1.3 only, enforce strict Cloudflare CIDR whitelisting for client IP restoration, install HTTP request rate-limiting pools, drop common scraper user-agents, and require execution of `nginx -t` validation before finalizing changes.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Create the workspace skill manifest directory and inject the deterministic Nginx hardening rules.
Autonomous runtimes parse directory-specific rules to shape system prompts. We mount the SKILL.md specification to `.agents/skills/nginx-hardener` (for universal loaders) and link it into `.cursor/rules/` or Claude Code workspace configs so the agent automatically loads the hardening parameters upon reading Nginx configuration files.
mkdir -p .agents/skills/nginx-hardener && curl -fsSL https://askills.dev/api/skills/nginx-hardener/raw -o .agents/skills/nginx-hardener/SKILL.md---
name: "nginx-hardener"
description: "Harden Nginx reverse proxies with TLS 1.3, Cloudflare real IP, bot blocking, and gzip offloading."
category: "devops"
security_score: 98
---
# Production Nginx Hardener SOP
1. Enforce TLS 1.3 exclusively: `ssl_protocols TLSv1.3;`
2. Extract Real Client IP solely from verified Cloudflare CIDRs via `ngx_http_realip_module`.
3. Rate limiting MUST be initialized in the `http` block via `limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;`.
4. Close connections instantly for known malicious user agents via `$bad_bot` mapping.
5. Run `nginx -t -c <file>` to assert configuration validity prior to completing task.Store the skill in `.agents/skills/` and symlink into `.cursorrules` or `.claude.md` to conserve agent context tokens by avoiding file duplication across multiple runtime config paths.
AI agents operating in unprivileged sandboxes cannot bind port 80 or 443 directly. Instruct the agent to test bindings against unprivileged ports (8080/8443) or validate syntax with the `-t` flag without starting systemd units.
Environment Secrets & Cloudflare Ingress Pinning
Inject Cloudflare trusted IP ranges into a dedicated include file without exposing sensitive workspace variables.
To prevent IP spoofing when running behind Cloudflare or another edge reverse proxy, the agent must generate a dedicated `cloudflare_ips.conf` based on official Cloudflare IP ranges. This ensures `set_real_ip_from` directives are isolated and modular.
mkdir -p conf/nginx/conf.d && curl -s https://www.cloudflare.com/ips-v4 | awk '{print "set_real_ip_from " $1 ";"}' > conf/nginx/conf.d/cloudflare_ips.conf && echo "real_ip_header CF-Connecting-IP;" >> conf/nginx/conf.d/cloudflare_ips.confSeparate dynamic network blocks (like proxy IP whitelists) from main `nginx.conf` so agents do not re-read and consume tokens on long IP lists during iterative code refactoring.
Do not hardcode production private TLS keys into agent instruction files or prompts. Reference file paths (`/etc/ssl/certs/...`) and keep private keys in encrypted secrets stores.
Intent Matching & Trigger Invocation
Trigger deterministic proxy generation using validated prompt parameters.
Provide the agent with explicit reverse proxy targets and security requirements. The skill's frontmatter matches keywords such as 'reverse proxy', 'TLS 1.3', 'rate limit', and 'harden nginx', shifting the agent into strict enforcement mode.
Specify upstream ports and service names in your prompt so the agent generates precise `upstream` upstream blocks rather than generic localhost pointers.
Ensure that your prompt does not instruct the agent to generate deprecated directives like `ssl_ciphers HIGH:!aNULL:!MD5;` which are redundant and conflicting when TLS 1.3 is enforced.
Verification, Linting & Output Quality Gate
Execute non-destructive Nginx configuration verification inside an isolated container sandbox.
The skill mandates a self-healing verification cycle. The agent must run an automated syntax check using a temporary container or isolated process before marking the task complete.
docker run --rm -v "$PWD/conf/nginx:/etc/nginx:ro" nginx:alpine nginx -tUse `git diff --stat conf/nginx/` before committing agent-generated configs to confirm no global default buffers or timeouts were unintentionally altered.
Container sandboxes may fail if paths inside `nginx.conf` reference host-specific directories that are not mounted into the test container.
Real-World Scenario: Harden an Edge Reverse Proxy for a Node.js Microservice behind Cloudflare
“Generate a production-hardened Nginx reverse proxy configuration for an internal microservice running at 127.0.0.1:3000. Apply the nginx-hardener skill: enforce TLS 1.3, isolate Cloudflare client IPs, block Semrush/Ahrefs bots with 444 responses, add strict rate limiting, and test the syntax.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent attempted to declare a shared memory rate-limiting zone inside a `server` or `location` block instead of the root `http` block context.
Move the `limit_req_zone` declaration to an included file loaded directly by the `http` block: `echo 'limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;' > conf/nginx/conf.d/rate_limits.conf`Root Cause: The agent enabled `ssl_stapling on;` without specifying the intermediate CA bundle via `ssl_trusted_certificate` or using a self-signed certificate in the workspace.
Add the CA chain path to the SSL configuration: `sed -i 's|ssl_stapling on;|ssl_stapling off; # Disabled in local/staging without intermediate bundle|g' conf/nginx/nginx.conf`Frequently Asked Questions (Production Nginx Hardener & Proxy SOP)
Q:Can I use Production Nginx Hardener & Proxy across Codex, Claude Code, and Cursor simultaneously?
Yes. The SKILL.md specification is completely runtime-agnostic. You can mount it within `.cursor/rules/`, include it in your Claude Code system prompt file (`.claude.md`), or place it into the workspace root for Codex and Windsurf agents.
Q:How does Production Nginx Hardener & Proxy prevent context window overflow during long agent sessions?
By establishing declarative constraints and delegating heavy configurations (such as IP CIDR tables and bot lists) to modular include files (`include conf.d/*.conf;`), keeping core agent reasoning loops under 400 tokens.
Q:Does this skill require escalated root or container permissions?
No. The skill is designed to operate safely inside unprivileged workspaces with a security score of 98/100. All validation steps use non-root dry runs (`nginx -t -p . -c ...`) or unprivileged Docker test containers.
Ready to equip your autonomous agent with Production Nginx Hardener & Proxy?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.