install
source · Clone the upstream repo
git clone https://github.com/ComeOnOliver/skillshub
Claude Code · Install into ~/.claude/skills/
T=$(mktemp -d) && git clone --depth=1 https://github.com/ComeOnOliver/skillshub "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/pproenca/dot-skills/nginx-c-modules" ~/.claude/skills/comeonoliver-skillshub-nginx-c-modules && rm -rf "$T"
manifest:
skills/pproenca/dot-skills/nginx-c-modules/SKILL.mdsource content
nginx.org C Module Development Best Practices
Comprehensive development guide for nginx C modules, derived from the official nginx development documentation and community expertise. Contains 49 rules across 8 categories, prioritized by impact to guide correct module implementation and prevent common crashes, memory leaks, and undefined behavior.
When to Apply
Reference these guidelines when:
- Writing new nginx C modules (handlers, filters, upstream, load-balancers)
- Implementing configuration directives and merge logic
- Managing memory with nginx pools and shared memory zones
- Handling the HTTP request lifecycle (body reading, subrequests, finalization)
- Working with nginx's event loop, timers, and thread pools
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Memory Management | CRITICAL | |
| 2 | Request Lifecycle | CRITICAL | |
| 3 | Configuration System | HIGH | |
| 4 | Handler Development | HIGH | |
| 5 | Filter Chain | MEDIUM-HIGH | |
| 6 | Upstream & Proxy | MEDIUM | |
| 7 | Event Loop & Concurrency | MEDIUM | |
| 8 | Data Structures & Strings | LOW-MEDIUM | |
Quick Reference
1. Memory Management (CRITICAL)
- Use Pool Allocation Instead of Heap mallocmem-pool-allocation
- Check Every Allocation Return for NULLmem-check-allocation
- Use ngx_pcalloc for Struct Initializationmem-pcalloc-structs
- Register Pool Cleanup Handlers for External Resourcesmem-cleanup-handlers
- Use ngx_pnalloc for String Data Allocationmem-pnalloc-strings
- Avoid Relying on ngx_pfree for Pool Allocationsmem-pfree-limitations
- Use Slab Allocator for Shared Memory Zonesmem-shared-slab
2. Request Lifecycle (CRITICAL)
- Finalize Requests Exactly Oncereq-finalize-once
- Never Access Request After Finalizationreq-no-access-after-finalize
- Handle Request Body Reading Asynchronouslyreq-body-async
- Discard Request Body When Not Reading Itreq-discard-body
- Use Post-Subrequest Handlers for Completionreq-subrequest-completion
- Increment Request Count Before Async Operationsreq-count-reference
- Return After Internal Redirectreq-internal-redirect
3. Configuration System (HIGH)
- Initialize Config Fields with UNSET Constantsconf-unset-init
- Merge All Config Fields in merge_loc_confconf-merge-all-fields
- Use Correct Context Flags for Directivesconf-context-flags
- Terminate Commands Array with ngx_null_commandconf-null-command
- Use Custom Handlers for Complex Directive Parsingconf-custom-handler
- Set Unused Module Context Callbacks to NULLconf-module-ctx-null
- Write Correct config Build Script for Module Compilationconf-build-config
4. Handler Development (HIGH)
- Send Header Before Body Outputhandler-send-header-first
- Set last_buf Flag on Final Bufferhandler-last-buf
- Register Phase Handlers in postconfigurationhandler-phase-registration
- Use content_handler for Location-Specific Response Generationhandler-content-handler
- Return HTTP Status Codes for Error Responseshandler-error-page
- Use header_only for Empty Body Responseshandler-empty-response
- Use Module Context for Per-Request Statehandler-module-ctx
- Register Custom Variables in preconfigurationhandler-add-variable
5. Filter Chain (MEDIUM-HIGH)
- Save and Replace Top Filter in postconfigurationfilter-registration-order
- Always Call Next Filter in the Chainfilter-call-next
- Distinguish Main Request from Subrequest in Filtersfilter-check-subrequest
- Iterate Buffer Chains Using cl->next Patternfilter-buffer-chain-iteration
- Set Buffering Flag When Accumulating Response Datafilter-buffering-flag
6. Upstream & Proxy (MEDIUM)
- Build Complete Request Buffer in create_requestupstream-create-request
- Parse Upstream Response Incrementally in process_headerupstream-process-header
- Track Failures in Peer free Callbackupstream-peer-free
- Clean Up Resources in finalize_request Callbackupstream-finalize
- Enable Keepalive for Upstream Connectionsupstream-connection-reuse
7. Event Loop & Concurrency (MEDIUM)
- Never Use Blocking Calls in Event Handlersevent-no-blocking
- Delete Timers Before Freeing Associated Dataevent-timer-management
- Call ngx_handle_read/write_event After I/O Operationsevent-handle-read-write
- Offload Blocking Operations to Thread Poolevent-thread-pool
- Use Posted Events for Deferred Processingevent-posted-events
8. Data Structures & Strings (LOW-MEDIUM)
- Never Assume ngx_str_t Is Null-Terminatedds-ngx-str-not-null-terminated
- Use ngx_string Macro Only with String Literalsds-ngx-str-set-literals
- Use ngx_cpymem for Sequential Buffer Writesds-cpymem-pattern
- Iterate ngx_list_t Using Part-Based Patternds-list-iteration
- Build Hash Tables During Configuration Onlyds-hash-readonly
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 |