tailuge/nchan-expert
Overview
This skill delivers expert, actionable guidance for configuring, scaling, securing, and troubleshooting Nchan, the high-performance pub/sub module for Nginx. It focuses on endpoint setup (publishers, subscribers, pubsub), Redis-backed horizontal scaling, security patterns, observability, and containerization. Use it to get concise, production-ready configuration patterns and troubleshooting steps.
How this skill works
The skill inspects common Nginx + Nchan configuration needs and provides concrete directives, examples, and patterns for publishers, subscribers, and combined pubsub locations. It explains storage options including local in-memory and Redis modes, shows how to delegate authorization or hide internal IDs with X-Accel-Redirect, and outlines monitoring hooks such as nchan_stub_status and channel variables. It also includes testing and containerization guidance to validate setups and deploy Nchan in containers.
When to use it
- Creating HTTP or WebSocket publisher endpoints that accept messages reliably
- Implementing subscriber endpoints with WebSocket, EventSource (SSE), or long-polling
- Scaling Nchan horizontally using Redis (distributed, backup, or nostore modes)
- Locking down channels with authorization, internal redirects, and IP ACLs
- Diagnosing performance, connection counts, or handshake issues in production
Best practices
- Map Nginx locations explicitly: use nchan_publisher, nchan_subscriber, or nchan_pubsub for clarity
- Use Redis distributed mode for multi-node setups; choose backup/nostore only for specific persistence or broadcast needs
- Delegate authorization to an upstream app via nchan_authorize_request and use X-Accel-Redirect to avoid exposing channel internals
- Monitor using nchan_stub_status and nchan variables like $nchan_subscriber_count for real-time insights
- Compile Nchan into your Nginx build with multi-stage Dockerfiles and run containers as non-root with healthchecks
Example use cases
- High-throughput WebSocket chat: configure nchan_publisher for incoming posts and nchan_subscriber for many concurrent clients
- IoT telemetry ingestion: use Redis distributed storage across nodes for shardable, highly available ingestion
- Private channels with auth: use nchan_authorize_request and X-Accel-Redirect to enforce access without leaking channel IDs
- Metrics and debugging: enable nchan_stub_status and log channel events to track subscriber counts and message lifecycle
- Containerized deployment: multi-stage build for Nginx+Nchan, non-root runtime, and readiness/liveness checks
FAQ
Use Distributed for shared state across nodes; Backup to persist local messages to Redis; Nostore for broadcast-only scenarios without shared storage.
How can I hide channel IDs from clients?
Use X-Accel-Redirect to serve an internal location that maps a public path to the real channel ID, keeping IDs out of client-visible URLs.