Reverse Proxy and Network Setup Guide
Configure AiPBX to safely run behind existing HTTP/HTTPS reverse proxies (such as Nginx, Caddy, Traefik, HAProxy, or Apache). Manage trusted proxy IPs to safely forward real client IP addresses, generate sample configurations, and inspect required network ports and firewall scripts.
- HTTPS between the proxy and AiPBX only works with HAProxy. Port 443 tells HTTPS from TURNS by ALPN, and Nginx, Apache, Caddy and Traefik do not send it on the connections softphones need. With those, end TLS at the proxy and use a private network to reach AiPBX.
10.218.49.1
Direct / Untrusted
—
—
10.218.49.1
Pre-configured, production-ready configuration snippets including WebRTC WebSocket (/ws) upgrade handling and client IP headers.
# ==============================================================================
# /etc/nginx/sites-available/aipbx.conf
# AiPBX Reverse Proxy Configuration (Nginx)
# External FQDN: demo.aipbx.local
# Backend Target: http://10.218.49.190:80
#
# IMPORTANT: VoIP protocols (SIP 5060/5061 and RTP 10000-20000 UDP) MUST bypass
# this HTTP proxy and connect directly to the server host.
# ==============================================================================
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
upstream aipbx_web_backend {
server 10.218.49.190:80;
keepalive 32;
}
# Redirect HTTP to HTTPS
server {
listen 80;
listen [::]:80;
server_name demo.aipbx.local;
location /.well-known/acme-challenge/ {
root /var/www/html;
}
location / {
return 301 https://$host$request_uri;
}
}
# Main HTTPS Server
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name demo.aipbx.local;
# TLS Certificates (manage via certbot or centralized PKI)
ssl_certificate /etc/letsencrypt/live/demo.aipbx.local/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/demo.aipbx.local/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 1d;
client_max_body_size 64M;
# 1. WebRTC WebSocket Signaling (Softphones)
location /ws {
proxy_pass http://aipbx_web_backend/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
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;
# Keep alive for long WebRTC sessions
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
}
# 2. Main Portal, Chat WebSocket & Desk Phone Provisioning
location / {
proxy_pass http://aipbx_web_backend;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
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;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
proxy_connect_timeout 60s;
proxy_send_timeout 3600s;
proxy_read_timeout 3600s;
proxy_buffering off;
}
}
Comprehensive matrix of all network ports used by AiPBX, showing protocols, required exposure, and reverse proxy bypass status.
| Port Range | Protocol | Service / Purpose | Access Scope | Proxy Bypass | Description & Notes |
|---|---|---|---|---|---|
| 5060 | UDP / TCP | SIP Signaling | Public / LAN | Direct (Bypass) | Standard SIP phone signaling, PBX trunks, and softphone registrations. |
| 5061 | TCP | SIP-TLS Signaling | Public / LAN | Direct (Bypass) | Secure encrypted SIP signaling via TLS. |
| 10000-20000 | UDP | RTP / SRTP Media | Public / LAN | Direct (Bypass) | Real-time Transport Protocol streams for two-way audio and video calls. |
| 80 | TCP | HTTP Web Portal / ACME | Public / LAN | Proxied (HTTP/WS) | Web administration portal, phone auto-provisioning, and Let's Encrypt HTTP-01 challenge. |
| 443 | TCP | HTTPS Web Portal | Public / LAN | Proxied (HTTP/WS) | Encrypted Web portal, REST API endpoints, and WebSocket proxying. |
| 8089 | TCP | Asterisk WSS (WebRTC) | Localhost (127.0.0.1) | Proxied (HTTP/WS) | Not used by clients and never opened: browsers and the mobile apps reach WebRTC signaling over 443 at /ws. |
| 8088 | TCP | Asterisk HTTP / WS | Localhost (127.0.0.1) | Proxied (HTTP/WS) | Behind /ws of the portal. A reverse proxy connects to the portal, not to this port. |
| 3478 / 5349 | UDP / TCP | STUN / TURNS (coturn) | Public | Direct (Bypass) | NAT traversal relay for WebRTC media behind symmetric NAT or corporate firewalls. |
| 69 | UDP | TFTP Provisioning | LAN only | Direct (Bypass) | Legacy desk phone configuration and firmware downloads. |
| 9061 | UDP | HEP / Homer SIP Capture | Internal / Monitoring | Direct (Bypass) | Encapsulated SIP packet capture streaming for Homer VoIP monitoring. |
| 5038 | TCP | AMI (Asterisk Manager) | Localhost only (127.0.0.1) | Direct (Bypass) | Internal Asterisk management interface. NEVER expose to the internet. |
| 3306 | TCP | MariaDB Database | Localhost only (127.0.0.1) | Direct (Bypass) | Core PBX database. Bound to 127.0.0.1 only. |
#!/usr/bin/env bash # AiPBX UFW Firewall Rules Setup # Run with root privileges set -euo pipefail # 1. Reset or set baseline defaults ufw default deny incoming ufw default allow outgoing # 2. Management & Web ufw allow 22/tcp comment 'SSH Access' ufw allow 80/tcp comment 'AiPBX Web Portal / HTTP-01' ufw allow 443/tcp comment 'AiPBX Web Portal / HTTPS' # 3. VoIP Signaling (MUST route directly to server) ufw allow 5060/udp comment 'SIP Signaling UDP' ufw allow 5060/tcp comment 'SIP Signaling TCP' ufw allow 5061/tcp comment 'SIP-TLS Signaling TCP' # 4. RTP Audio / Video Media Range (Direct UDP) ufw allow 10000:20000/udp comment 'AiPBX RTP Media Streams' # 5. WebRTC STUN / TURNS Relay ufw allow 3478/udp comment 'STUN / TURN UDP' ufw allow 3478/tcp comment 'STUN / TURN TCP' ufw allow 5349/tcp comment 'TURNS TLS' # 6. Internal Desk Phone Provisioning (Restrict to local subnet if desired) # ufw allow from 192.168.1.0/24 to any port 69 proto udp comment 'TFTP Phone Provisioning' # Enable firewall ufw --force enable ufw status verbose