This specification is maintained by the AgentRules Working Group. Have enhancements or want to claim maintainership?Submit Specification →
devopshigh PriorityID: nginx-reverse-proxy-hardening

Nginx Reverse Proxy Hardening & TLS 1.3 Standard

Guardrails for Nginx configuration: TLS 1.3 cipher suites, HTTP Strict Transport Security (HSTS), rate limiting zones, and prevention of hop-by-hop header leakage.

Prohibited Anti-Pattern: AI forgets proxy_set_header Host $host or leaves server_tokens on, exposing the exact Nginx version.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: Nginx Reverse Proxy Hardening & TLS 1.3 Standard - Guardrails for Nginx configuration: TLS 1.3 cipher suites, HTTP Strict Transport Security (HSTS), rate limiting zones, and prevention of hop-by-hop header leakage.
globs: nginx/**/*.conf, nginx.conf
alwaysApply: false
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/nginx-reverse-proxy-hardening"
---

# Nginx Reverse Proxy Hardening & TLS 1.3 Standard

> **Severity**: HIGH | **Category**: devops
> **Anti-Pattern Warning**: AI forgets proxy_set_header Host $host or leaves server_tokens on, exposing the exact Nginx version.

## System Constraints
You are an Nginx systems engineer. Harden configurations: turn off server_tokens. Enforce TLS 1.2/1.3 with secure ciphers. Include HSTS, X-Content-Type-Options: nosniff, and X-Frame-Options: DENY headers. Set up limit_req_zone to mitigate brute-force and DDoS attacks.

## Strict Guidelines
- Add server_tokens off; to avoid revealing Nginx version numbers to attackers.
- Enforce HSTS (Strict-Transport-Security: max-age=63072000; includeSubDomains; preload).
- Pass client identity headers (X-Forwarded-For, X-Real-IP) and preserve Host header.

## Bad vs Good Implementations
### Hardened Nginx Server Block with Rate Limiting

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Transmits traffic in plaintext, leaks server version, and drops upstream Host headers.
```nginx
# Anti-pattern: Vulnerable default Nginx config
server {
    listen 80;
    server_name example.com;
    location / {
        proxy_pass http://localhost:3000; # Host header lost, no TLS, version exposed!
    }
}
```

#### Production Standard (Correct)
> **Standard**: Secures TLS parameters, adds defense-in-depth headers, applies rate limits, and preserves client IP identity.
```nginx
# Production Standard: Hardened Nginx Reverse Proxy
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=20r/s;

server {
    listen 443 ssl http2;
    server_name example.com;

    server_tokens off;
    ssl_protocols TLSv1.2 TLSv1.3;
    ssl_prefer_server_ciphers on;

    add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header X-Frame-Options "DENY" always;

    location /api/ {
        limit_req zone=api_limit burst=10 nodelay;
        proxy_pass http://127.0.0.1:3000;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: Nginx Reverse Proxy Hardening & TLS 1.3 Standard

Nginx Reverse Proxy Hardening & TLS 1.3 Standard defines an industrial-grade behavioral standard for devops engineering. Guardrails for Nginx configuration: TLS 1.3 cipher suites, HTTP Strict Transport Security (HSTS), rate limiting zones, and prevention of hop-by-hop header leakage. Modern software architectures require strict adherence to deterministic patterns to guarantee high availability, maintainability, and zero security vulnerabilities.

Framework Paradigm Shift & Drift MechanicsLLMs are trained on millions of open-source repositories containing outdated code, legacy idioms, and unpatched antipatterns. When coding assistants generate implementations for this stack, they default to common statistical tokens: AI forgets proxy_set_header Host $host or leaves server_tokens on, exposing the exact Nginx version. Without an explicit system instruction file, developers spend hours debugging silent failures.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
AI Hallucination & Deprecation DriftAI forgets proxy_set_header Host $host or leaves server_tokens on, exposing the exact Nginx version.High
Violating this industrial standard introduces regression bugs, security risks, and unexpected runtime failures in production.
Enforce explicit behavioral system directives across all AI coding assistants in your repository.
Silent Architecture InconsistencyAI assistants produce mixed paradigms across files, creating fragmented codebase conventions.Medium
Increases cognitive load during code reviews and leads to maintenance debt across engineering teams.
Pin project conventions in .cursor/rules, CLAUDE.md, and AGENTS.md so all team agents follow identical guardrails.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Add server_tokens off

Add server_tokens off; to avoid revealing Nginx version numbers to attackers.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Enforce HSTS (Strict-Transport-Security

Enforce HSTS (Strict-Transport-Security: max-age=63072000; includeSubDomains; preload).

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Pass client identity headers (X-Forwarded-For, X-Real-IP) and preserve Host header.

Pass client identity headers (X-Forwarded-For, X-Real-IP) and preserve Host header.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Why is Nginx Reverse Proxy Hardening & TLS 1.3 Standard critical for AI coding assistants?

Guardrails for Nginx configuration: TLS 1.3 cipher suites, HTTP Strict Transport Security (HSTS), rate limiting zones, and prevention of hop-by-hop header leakage. Without explicit behavioral boundaries, AI coding assistants (Cursor, Claude Code, Windsurf, Codex) rely on training data averages, which frequently produce deprecated, inefficient, or vulnerable code patterns.

Q:How does adopting this rule prevent AI hallucinations?

This rule explicitly declares what the AI must avoid (AI forgets proxy_set_header Host $host or leaves server_tokens on, exposing the exact Nginx version.) and prescribes verified positive examples. Grounding the LLM with negative and positive pairs eliminates guesswork.

Q:Which AI coding environments are supported?

This specification is multi-platform compatible: Cursor (.cursor/rules/*.mdc & .cursorrules), Anthropic Claude Code (CLAUDE.md), Windsurf (.windsurfrules), Codex / Cline (AGENTS.md), and GitHub Copilot (.github/copilot-instructions.md).

Q:Can I combine this rule with other technology stacks?

Yes. Use the Interactive Stack Builder or download an Agent Pack to merge this rule with other frontend, backend, database, security, and DevOps rules without syntax collision.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

1 Rule in Stack

Nginx