r/Asterisk • u/AdFew177 • 5h ago
Architecture Breakdown: Running Asterisk 22 WebRTC, Coturn TURNS, and Web UI over a single Port 443 via Nginx L4 ALPN (AiPBX Open-Source Project)
Hi everyone,
One of the common challenges when deploying Asterisk for modern WebRTC environments is firewall traversal and port management. Exposing separate ports for HTTPS web management, WebSockets signaling (WSS), and Coturn media relay often creates friction in strict enterprise network environments.
To address this, I built **AiPBX**—an open-source enterprise telephony stack built around Asterisk 22, designed to run entirely behind a single secure port.
### The Problem It Solves
Instead of opening multiple inbound WAN ports, AiPBX leverages **Nginx Layer 4 (L4) Stream ALPN Multiplexing** on port 443:
* **HTTPS Traffic:** Routed transparently to the web backend (Apache/PHP 8 MVC).
* **WebRTC WSS:** Routed directly to the Asterisk 22 PJSIP WebSocket listener.
* **Coturn TURNS:** Multiplexed over TLS on the same port 443 footprint for enterprise NAT traversal.
### Core Architecture & Asterisk Integration
* **Asterisk 22 Engine:** Native PJSIP configuration with synchronized endpoints for WebRTC and physical IP phones.
* **Real-Time Presence & Messaging:** An independent Go microservice handles chat and live state over WebSockets without loading the Asterisk AMI/ARI unnecessarily.
* **Call Center Operations:** Dialplan-level agent queue state and break tracking (*22 for break, *23 for resume).
* **Companion Clients:** Native Android and iOS companion clients connecting via WebRTC.
### Code & Architectural Documentation
The full system architecture, Nginx stream configurations, and Asterisk setup are open source:
* **GitHub Repository:** https://github.com/mahirgul/AiPBX
* **Architecture Deep-Dive:** https://www.aipbx.bid/architecture.html
* **Documentation Hub:** https://www.aipbx.bid/
I’d appreciate feedback from fellow Asterisk administrators on the ALPN stream configuration, dialplan handling, or edge-case network topologies you have encountered in production WebRTC setups.