nginx.org C Module Directive Design Best Practices
Comprehensive directive design guide for nginx C module authors, focused on creating clear, consistent, and admin-friendly configuration interfaces. Contains 46 rules across 8 categories, prioritized by impact to guide decisions about what to expose, how to name it, and how to evolve it safely.
When to Apply
Reference these guidelines when:
Deciding which values to expose as directives vs hardcode
default-performance-optin - Make Performance Features Opt-In
default-safety-on - Default Security Settings to Restrictive Values
default-generous-timeouts - Default Timeouts to Generous Values
default-zero-unlimited - Use Zero to Mean Unlimited or Disabled for Numeric Limits
default-platform-aware-buffers - Use Platform-Aware Buffer Size Defaults
6. Validation & Error Messages (MEDIUM)
valid-parse-time-check - Validate All Directive Values at Config Parse Time
valid-show-invalid-value - Include the Invalid Value in Error Messages
valid-suggest-range - Include Valid Range or Format in Error Messages
valid-conflict-detection - Detect Conflicting Directives at Merge Time
valid-actionable-guidance - Provide Actionable Guidance in Error Messages
7. Variable Design (MEDIUM)
var-runtime-data-only - Expose Variables for Per-Request Runtime Data Only
var-naming-convention - Name Variables with Module Prefix and Descriptive Suffix
var-dynamic-prefix - Use Dynamic Prefix Variables for Key-Value Data
var-lazy-evaluation - Leverage Lazy Evaluation for Expensive Variables
var-in-directive-values - Support Variables in Directive Values Only When Per-Request Variation Is Needed
var-read-only-diagnostics - Expose Read-Only Diagnostic Variables for Observability
8. Evolution & Compatibility (LOW-MEDIUM)
compat-deprecation-warning - Log Warnings for Deprecated Directives Before Removal
compat-alias-old-directive - Keep Old Directive Name as an Alias
compat-multi-version-window - Maintain a Multi-Version Deprecation Window
compat-document-migration - Document Migration Path in Both Old and New Directive Documentation
How to Use
Read individual reference files for detailed explanations and code examples:
Section definitions - Category structure and impact levels
Rule template - Template for adding new rules
Reference Files
File
Description
references/_sections.md
Category definitions and ordering
assets/templates/_template.md
Template for new rules
metadata.json
Version and reference information
1---2name: nginx-c-module-design3description: nginx.org C Module Directive Design Best Practices4---5# nginx.org C Module Directive Design Best Practices67Comprehensive directive design guide for nginx C module authors, focused on creating clear, consistent, and admin-friendly configuration interfaces. Contains 46 rules across 8 categories, prioritized by impact to guide decisions about what to expose, how to name it, and how to evolve it safely.89## When to Apply1011Reference these guidelines when:12- Deciding which values to expose as directives vs hardcode13- Naming new directives and choosing argument types14- Selecting scope placement (http, server, location)15- Setting default values and validation behavior16- Designing nginx variables for runtime data17- Deprecating or renaming existing directives1819## Companion Skills2021This skill focuses on **design decisions** (the "what" and "why"). For implementation mechanics, see:22- **nginx-c-modules** — C implementation: memory pools, request lifecycle, config parsing, handlers, filters23- **nginx-c-perf** — Performance: buffers, connections, locks, caching, timeouts24- **nginx-c-debug** — Debugging: crash diagnosis, GDB, tracing, sanitizers2526## Rule Categories by Priority2728| Priority | Category | Impact | Prefix |29|----------|----------|--------|--------|30| 1 | Exposure Decisions | CRITICAL | `expose-` |31| 2 | Naming Conventions | CRITICAL | `naming-` |32| 3 | Directive Types | HIGH | `type-` |33| 4 | Scope Design | HIGH | `scope-` |34| 5 | Default Values | MEDIUM-HIGH | `default-` |35| 6 | Validation & Error Messages | MEDIUM | `valid-` |36| 7 | Variable Design | MEDIUM | `var-` |37| 8 | Evolution & Compatibility | LOW-MEDIUM | `compat-` |3839## Quick Reference4041### 1. Exposure Decisions (CRITICAL)4243- [`expose-configurable-vs-hardcode`](references/expose-configurable-vs-hardcode.md) - Framework for Configurable vs Hardcoded Values44- [`expose-escape-hatch`](references/expose-escape-hatch.md) - Provide Escape Hatches for Hardcoded Defaults45- [`expose-feature-gate`](references/expose-feature-gate.md) - Use Feature Gates for Optional Behavior46- [`expose-too-many-directives`](references/expose-too-many-directives.md) - Avoid Over-Configuration47- [`expose-path-resource`](references/expose-path-resource.md) - Always Expose External Resource Paths48- [`expose-security-surface`](references/expose-security-surface.md) - Audit Security Implications of Every Exposed Directive49- [`expose-environment-dependent`](references/expose-environment-dependent.md) - Expose Values That Vary by Deployment Environment5051### 2. Naming Conventions (CRITICAL)5253- [`naming-module-prefix`](references/naming-module-prefix.md) - Use a Consistent Module Prefix for All Directives54- [`naming-sub-prefix-groups`](references/naming-sub-prefix-groups.md) - Group Related Directives with Sub-Prefixes55- [`naming-noun-over-verb`](references/naming-noun-over-verb.md) - Prefer Noun Phrases for Directive Names56- [`naming-no-abbreviations`](references/naming-no-abbreviations.md) - Avoid Custom Abbreviations in Directive Names57- [`naming-cross-module-consistency`](references/naming-cross-module-consistency.md) - Mirror Nginx Core Suffix Patterns for Analogous Directives58- [`naming-lowercase-underscore`](references/naming-lowercase-underscore.md) - Use Lowercase with Underscores Only5960### 3. Directive Types (HIGH)6162- [`type-flag-for-toggles`](references/type-flag-for-toggles.md) - Use NGX_CONF_FLAG for Binary Toggles63- [`type-enum-over-string`](references/type-enum-over-string.md) - Use Enum Slot for Known Value Sets64- [`type-time-size-units`](references/type-time-size-units.md) - Use Time and Size Slot Functions for Time and Size Values65- [`type-take-n-fixed-args`](references/type-take-n-fixed-args.md) - Use TAKE1/TAKE2/TAKE12 for Fixed Argument Counts66- [`type-one-more-lists`](references/type-one-more-lists.md) - Use 1MORE for Variable-Length Value Lists67- [`type-avoid-block`](references/type-avoid-block.md) - Avoid Block Directives for Features68- [`type-custom-handler-complex`](references/type-custom-handler-complex.md) - Use Custom Handlers for Complex Directive Parsing6970### 4. Scope Design (HIGH)7172- [`scope-default-three-levels`](references/scope-default-three-levels.md) - Default to http + server + location Scope73- [`scope-http-only-shared-resources`](references/scope-http-only-shared-resources.md) - Restrict Shared Resource Directives to http Level Only74- [`scope-server-connection-level`](references/scope-server-connection-level.md) - Use http + server Scope for Connection-Level Settings75- [`scope-avoid-if-context`](references/scope-avoid-if-context.md) - Do Not Support the if Context Unless Fully Tested76- [`scope-location-path-operations`](references/scope-location-path-operations.md) - Restrict Path-Routing Directives to Location Context7778### 5. Default Values (MEDIUM-HIGH)7980- [`default-zero-config-safe`](references/default-zero-config-safe.md) - Ensure Zero-Config Produces Safe Behavior81- [`default-performance-optin`](references/default-performance-optin.md) - Make Performance Features Opt-In82- [`default-safety-on`](references/default-safety-on.md) - Default Security Settings to Restrictive Values83- [`default-generous-timeouts`](references/default-generous-timeouts.md) - Default Timeouts to Generous Values84- [`default-zero-unlimited`](references/default-zero-unlimited.md) - Use Zero to Mean Unlimited or Disabled for Numeric Limits85- [`default-platform-aware-buffers`](references/default-platform-aware-buffers.md) - Use Platform-Aware Buffer Size Defaults8687### 6. Validation & Error Messages (MEDIUM)8889- [`valid-parse-time-check`](references/valid-parse-time-check.md) - Validate All Directive Values at Config Parse Time90- [`valid-show-invalid-value`](references/valid-show-invalid-value.md) - Include the Invalid Value in Error Messages91- [`valid-suggest-range`](references/valid-suggest-range.md) - Include Valid Range or Format in Error Messages92- [`valid-conflict-detection`](references/valid-conflict-detection.md) - Detect Conflicting Directives at Merge Time93- [`valid-actionable-guidance`](references/valid-actionable-guidance.md) - Provide Actionable Guidance in Error Messages9495### 7. Variable Design (MEDIUM)9697- [`var-runtime-data-only`](references/var-runtime-data-only.md) - Expose Variables for Per-Request Runtime Data Only98- [`var-naming-convention`](references/var-naming-convention.md) - Name Variables with Module Prefix and Descriptive Suffix99- [`var-dynamic-prefix`](references/var-dynamic-prefix.md) - Use Dynamic Prefix Variables for Key-Value Data100- [`var-lazy-evaluation`](references/var-lazy-evaluation.md) - Leverage Lazy Evaluation for Expensive Variables101- [`var-in-directive-values`](references/var-in-directive-values.md) - Support Variables in Directive Values Only When Per-Request Variation Is Needed102- [`var-read-only-diagnostics`](references/var-read-only-diagnostics.md) - Expose Read-Only Diagnostic Variables for Observability103104### 8. Evolution & Compatibility (LOW-MEDIUM)105106- [`compat-deprecation-warning`](references/compat-deprecation-warning.md) - Log Warnings for Deprecated Directives Before Removal107- [`compat-alias-old-directive`](references/compat-alias-old-directive.md) - Keep Old Directive Name as an Alias108- [`compat-multi-version-window`](references/compat-multi-version-window.md) - Maintain a Multi-Version Deprecation Window109- [`compat-document-migration`](references/compat-document-migration.md) - Document Migration Path in Both Old and New Directive Documentation110111## How to Use112113Read individual reference files for detailed explanations and code examples:114115- [Section definitions](references/_sections.md) - Category structure and impact levels116- [Rule template](assets/templates/_template.md) - Template for adding new rules117118## Reference Files119120| File | Description |121|------|-------------|122| [references/_sections.md](references/_sections.md) | Category definitions and ordering |123| [assets/templates/_template.md](assets/templates/_template.md) | Template for new rules |124| [metadata.json](metadata.json) | Version and reference information |
Run npx skillmds@latest add comeonoliver/nginx-c-module-design in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
nginx.org C Module Directive Design Best Practices It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
ComeOnOliver (@comeonoliver) published this skill. Their other Agent Skills are listed on their SkillMD profile.