Lesson 5 / Unit 2: Self-Hosted Stack
AWS Deployment
A test client connects, the first real call carries no audio, and signalling logs may show no error. The EC2 setup for LiveKit, port by port, so livekit.yaml and the security group agree.
You launch an instance, start the server, and a test client connects in seconds. Signalling works. Then the first real call joins and nobody hears anything.
Two useful first checks are addressing and firewall coverage. The server may advertise an address callers cannot reach, or the UDP port range in livekit.yaml and the one in the security group disagree. Inspect ICE state, captures and VPC Flow Logs as well as application logs.
The server itself is a single Go binary with modest needs, and those two sharp edges are the whole difficulty. This page walks through the setup (instance, network, livekit.yaml, security group) so both places agree on day one, and sizes the port range on purpose. What happens when a node outgrows its range is its own story, told in port exhaustion before CPU.
Instance Selection
Use a compute-optimised instance in a public subnet with a public IP. Media forwarding is CPU and network, so memory-heavy instance families are not automatically the best fit, and LiveKit’s deployment guide recommends compute-optimised types too.
The public IP is the part people try to avoid. Media must reach the machine directly: RTP is UDP flowing to one specific node, so placing the SFU’s media ports behind a load balancer does not work, and the balancer adds nothing but confusion. Signalling is different. Port 7880 is plain HTTP and WebSocket, and it can sit behind a load balancer or reverse proxy that terminates TLS.
Attach an Elastic IP. An ordinary EC2 public IP is released when the instance stops and a new one is assigned on start, and every client and carrier you configured is then pointing at an address you no longer own.
Network Ports
Three port groups, two of them plain TCP. This is where deployments fail:
| Port | Purpose |
|---|---|
| 443 / 7880 TCP | Signalling, API, WebSocket |
| 7881 TCP | ICE over TCP fallback |
| 50000-60000 UDP | The RTP media range: one config, one security group rule, sized deliberately |
Two of the three port groups are plain TCP rules. The one we highlight is the RTP range: it lives in two places, and when they disagree media is dropped with nothing in any log.
As inbound security group rules, that looks like this:
| Protocol | Port range | Source | Purpose |
|---|---|---|---|
| TCP | 443 | 0.0.0.0/0 | Signalling over TLS |
| TCP | 7880 | Your TLS load balancer only | API and WebSocket |
| TCP | 7881 | 0.0.0.0/0 | ICE over TCP |
| UDP | 50000-60000 | 0.0.0.0/0 | RTP media |
| UDP | 3478 | 0.0.0.0/0 | Embedded TURN/UDP (optional) |
The TURN row only applies if you enable the embedded TURN server; the TURN lesson covers when you need it. If the SIP service runs on the same instance, it brings its own signalling port and its own RTP range, both covered in self-hosted SIP. LiveKit’s ports and firewall reference lists every port and the config key that sets it.
With the AWS CLI, the media rule is one command:
aws ec2 authorize-security-group-ingress \ --group-id sg-0123456789abcdef0 \ --protocol udp --port 50000-60000 \ --cidr 0.0.0.0/0Server Configuration
Five keys under rtc decide whether media flows. Here they are with the values from LiveKit’s recommended production config:
port: 7880rtc: tcp_port: 7881 port_range_start: 50000 port_range_end: 60000 # Discover the public IP via STUN and advertise it to clients. use_external_ip: true # Only if STUN picks the wrong address: set use_external_ip to false # and give the public IP (your Elastic IP) explicitly. # node_ip: 203.0.113.10keys: your-api-key: your-api-secretStart the server with livekit-server --config /etc/livekit.yaml. The full list of keys is in LiveKit’s config-sample.yaml. Once you add a second node, a redis block joins this file; the multi-node lesson covers it.
Firewall Coverage
The RTP range in livekit.yaml and the UDP range in the security group must cover the configured ports. If they drift, the server hands out ports the firewall blocks.
Here is why that hurts. Security groups only have allow rules, so a media port the firewall does not permit is dropped before it reaches the machine, and application logs may miss the drop. The server never sees the packet, so it cannot log it. The call connects, and carries silence.
That failure mode gets a full lesson in unit 5, because it found us at 612 concurrent calls.
The RTP range is written twice: once in the server config, once in the security group. When the two disagree, calls connect and carry silence, and packet captures or network flow logs may be needed.
Port Budget
First choose range mode or UDP multiplexing. The port reference documents rtc.udp_port for mux; when enabled, the range settings are not used. The older 18.3 counter below is an unverified case-study input, not a LiveKit default.
Here is the arithmetic with the default range:
| Quantity | Value |
|---|---|
| Default range, 50000 to 60000 | 10,001 ports |
| Assumed ports per call | 18.3 |
| Calls at exhaustion | 10,001 / 18.3, which is near 550 |
| Ports at 400 calls | 400 x 18.3 = 7,320 (73% of the range) |
That arithmetic only holds if 18.3 represents distinct allocated local ports within that range. Our saved report does not establish that. Port Capacity explains how to validate the counter before sizing from it.
Whatever range you configure is a capacity decision. If you widen it, widen the security group first and the server config second, so there is never a moment where the server offers ports the firewall drops.
Public Addressing
The server must announce the public IP that clients can reach. The private address the instance sees is useless to a caller outside the VPC. EC2 maps the public address onto the instance’s private one through one-to-one NAT, so the machine only sees its private VPC address on its own interface.
use_external_ip: true makes the server discover the public address with STUN and advertise that; if discovery ever picks the wrong one, turn it off and set node_ip to the Elastic IP by hand. Behind EC2’s NAT, this line decides whether media flows at all. Its subtler cousin, where the address is right and the port is still wrong, is the one-way audio lesson.
Common mistake
The whole deployment fits in a systemd unit, a config file, and a handful of security group rules. Resist the instinct to add layers. Every proxy, balancer, or sidecar between callers and the SFU’s media ports is a place for media to die invisibly, and unit 5 is a tour of what that costs.
Common questions
Which ports does LiveKit need open on AWS?
TCP 443 or 7880 for signalling and the API, TCP 7881 for ICE over TCP, and the UDP RTP range (50000-60000 by default) for media. The UDP range in the security group must allow the range configured in livekit.yaml.
Can LiveKit run behind an AWS load balancer?
Signalling can: port 7880 can sit behind a load balancer that terminates TLS. Media cannot. RTP is UDP flowing to one specific node, so the instance needs a public IP and the RTP range must reach it directly.
How big should the LiveKit RTP port range be?
Size it from ports per call. Measure unique allocated local ports for your transport mode and call topology. The saved 18.3 counter is not a verified allocation rate. UDP mux uses a different model.
We do this work for teams shipping voice agents: Self-Hosted Voice Agent .
Edit this lesson on GitHub ↗Discussion
Questions, corrections and war stories welcome. Sign in with GitHub to comment.