Do you really need your own RTMP server?
Before the commands, it is worth asking whether you need one at all. The answer depends on your situation.
When your own server makes sense
- Full control: security or compliance policies require the stream to pass only through your infrastructure.
- Internal network: corporate broadcasts that must never touch the public internet.
- Testing and development: you are building an app and need a test endpoint.
- Learning: you want to understand how RTMP works from the inside.
When a managed platform is the better choice
- Larger audiences: past roughly 200 concurrent viewers, a single server runs out of output bandwidth, and scaling with a CDN is a project of its own.
- Nobody on call: a server nobody maintains is a vulnerable server.
- Cost: a server plus CDN, monitoring and maintenance hours usually costs more than a managed service.
- Restream: relaying to several platforms takes significant extra setup, and every destination leaves from your server's upload.
Setting up an RTMP server that works for tests is easy. Setting up one that is stable, secure and scalable in production is serious engineering work. If your business depends on streaming, consider a managed platform and spend your effort on the content.
The fastest option: a local RTMP server with MediaMTX
If you want a private RTMP server on your own computer, to test OBS or to feed screens on your office network, MediaMTX is the quickest path. It is a single program for Windows, macOS and Linux, with no dependencies.
- Download the build for your system from the project's official releases page and unzip it.
- Run mediamtx (mediamtx.exe on Windows). With the default configuration it listens for RTMP on port 1935 and serves HLS on port 8888.
- In OBS, open Settings, Stream, choose Custom and enter rtmp://localhost/live as the server and mystream as the stream key.
- Start streaming and open http://localhost:8888/live/mystream in a browser: MediaMTX serves a small player page there.
To reach it from other devices on the same network, replace localhost with the computer's local IP address and allow those ports in its firewall. That is all you need for tests and local screens. For an audience on the internet you need a server with a public IP, which is what the rest of this guide covers.
How to install an RTMP server on Ubuntu with Nginx
Nginx with the RTMP module is the most popular and cheapest way to run an RTMP server on the internet. It is open source, light and runs on any Linux. These are the resources to plan for:
| Resource | Minimum | Recommended |
|---|---|---|
| CPU | 2 vCPU | 4 or more vCPU |
| RAM | 2 GB | 4 to 8 GB |
| Disk | 20 GB SSD | 100 GB SSD or more |
| Bandwidth | 100 Mbps | 1 Gbps |
| Operating system | Ubuntu 22.04 | Ubuntu 24.04 LTS |
On Ubuntu you do not need to compile anything: the RTMP module comes as a package that loads into the distribution's Nginx and gets security updates with the rest of the system.
# Update the system and install Nginx with the RTMP module
sudo apt update && sudo apt upgrade -y
sudo apt install -y nginx libnginx-mod-rtmp
# Folder where Nginx will write the HLS segments
sudo mkdir -p /var/www/hls
sudo chown www-data:www-data /var/www/hls Compiling Nginx from source with the module is still possible if you need a community fork with extra fixes, but the package is the easier path to keep patched.
Configure RTMP, HLS and a private stream key
Add this block at the end of /etc/nginx/nginx.conf, outside the http block. It accepts publishers only after a key check, blocks RTMP playback from outside and writes HLS for viewers:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
# Ask the local check before accepting a publisher
notify_method get;
on_publish http://127.0.0.1:8081/auth;
# Viewers watch HLS, not RTMP
allow play 127.0.0.1;
deny play all;
hls on;
hls_path /var/www/hls;
hls_fragment 2s;
hls_playlist_length 12s;
}
}
} Then create /etc/nginx/sites-available/rtmp-hls with two small servers: one that only the machine itself can reach, which validates the key and exposes the stats, and one that serves HLS on port 8080.
server {
listen 127.0.0.1:8081;
location = /auth {
if ($arg_pwd = "CHANGE-THIS-SECRET") {
return 200;
}
return 403;
}
location /stat {
rtmp_stat all;
}
}
server {
listen 8080;
location /hls/ {
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /var/www;
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
}
} Enable the site, check the syntax, reload, and open the firewall for SSH, RTMP and HLS:
sudo ln -s /etc/nginx/sites-available/rtmp-hls /etc/nginx/sites-enabled/
sudo nginx -t && sudo systemctl reload nginx
sudo ufw allow OpenSSH
sudo ufw allow 1935/tcp
sudo ufw allow 8080/tcp
sudo ufw enable How the key works: in OBS the stream key is mystream?pwd=CHANGE-THIS-SECRET. Nginx passes the pwd parameter to the local check, which answers 200 to accept the publisher or 403 to reject it, and the public playlist is named only after mystream, so the secret never appears in the viewers' URL. The 2-second hls_fragment matches the keyframe interval you will set in OBS, and running curl http://127.0.0.1:8081/stat on the server shows the active streams.
Connect OBS and test playback
- In OBS, open Settings, Stream, set the service to Custom, the server to rtmp://YOUR-SERVER-IP/live and the stream key to mystream?pwd=CHANGE-THIS-SECRET.
- In Settings, Output, with the output mode set to Advanced, choose CBR, a 2-second keyframe interval and a bitrate your upload can sustain: your stable upload should be about 1.5 times what you send.
- Start streaming. The playlist is at http://YOUR-SERVER-IP:8080/hls/mystream.m3u8.
- Open it in VLC (Media, Open Network Stream), in Safari, or in recent desktop versions of Chrome and Edge, which play HLS natively from version 141 and 142. On other browsers, a player built on hls.js does the job.
If it fails, the symptom usually points to the cause. If OBS cannot connect at all, port 1935 is closed in the server's firewall or at your cloud provider. If the server is reachable but OBS will not start streaming, the key check answered 403. If video arrives but no .m3u8 appears, Nginx cannot write to /var/www/hls: check the folder's owner. For the encoder side, our guide to professional streaming with OBS covers the settings in detail.
Alternatives on a server: MediaMTX and SRS
Nginx RTMP is the classic, but it has limits: no SRT, no WebRTC and no admin panel. These are the two modern alternatives worth knowing:
- MediaMTX: the same single binary from the local setup, also available as an official Docker image. It accepts RTMP, SRT, RTSP and WebRTC (WHIP) and serves HLS (including LL-HLS), WebRTC (WHEP), SRT and RTSP. Everything is configured in one YAML file, and there is no built-in transcoding.
- SRS (Simple Realtime Server): originally developed in China and possibly the most powerful open source option. It supports RTMP, HLS, HTTP-FLV, SRT and WebRTC, has an official Docker image and edge servers for clustering. Much of its community writes in Chinese, and it has no native transcoding either.
| Feature | Nginx RTMP | MediaMTX | SRS |
|---|---|---|---|
| RTMP ingest | Yes | Yes | Yes |
| SRT ingest | No | Yes | Yes |
| WebRTC | No | Yes | Yes |
| Transcoding | External FFmpeg | External FFmpeg | External FFmpeg |
| Difficulty | Low | Low | Medium |
| Docker | Community images | Official | Official |
Which protocol to use for ingest is a separate decision, and we compare the two main options in SRT vs RTMP.
Security you cannot skip
An RTMP server open to the internet without protection is an invitation to trouble. These are the critical points.
Publisher authentication
Without it, anyone who knows your IP can broadcast on your server. Use at least one of these: a secret stream key, an HTTP callback that checks the key against your own logic (the on_publish setup above) or an allow list of the IP addresses your encoders use.
Protecting the output
- Signed URLs that expire: Nginx's secure_link module can do it, with the token logic on you.
- Restrictive CORS: replace the asterisk in Access-Control-Allow-Origin with your own domain.
- HTTPS: never deliver HLS without TLS in production. Point a domain at the server and get a free Let's Encrypt certificate with certbot.
Server hardening
- A firewall with only the ports you use: SSH, 1935 and 443 (or 8080 while testing).
- SSH with keys, and password login disabled.
- Automatic security updates.
- Fail2ban against brute-force attempts.
- Monitoring that alerts you if the server goes down or the CPU spikes.
For comparison, this is what a managed service gives you without building it. On XtreamCast, SecureToken protects stream URLs in HLS, LL-HLS, WebRTC and SRT, geoblocking limits the countries that can watch and ShieldPower keeps the embedded player on your domains only. Ticket sales, logins and single sign-on for your audience stay on your own platform, which embeds the player. Details are on our streaming security page.
When to move from DIY to a managed platform
There is nothing wrong with starting on your own server. These are the signs it is time to consider a managed one:
- Your audience regularly passes 200 concurrent viewers and the server starts to struggle.
- You need a CDN, and building and running one costs more than adding Global CDN to a managed service as an add-on.
- You want to relay to YouTube, Facebook and other platforms, and maintaining a push or an FFmpeg process for each one has become a headache. Restream does it with a toggle per destination.
- Recordings are filling your disk. Recording Cloud records in the cloud as MP4.
- An event failed because of infrastructure, and it cost you money or credibility.
- You spend more time maintaining the server than making content.
If you want to start without installing anything, the free video plan gives you RTMP and SRT ingest, a player for your website with a watermark and one restream to a social network, for up to 10 concurrent viewers at 1,500 kbps. Moving an existing setup is mostly a matter of changing the server URL and key in your encoder (OBS, vMix, Wirecast) and replacing the embed on your site. The cost comparison, with real numbers, is in managed RTMP server vs self-hosted Nginx.
Skip the server maintenance
RTMP and SRT ingest with HLS delivery, a player for your website and one restream, free for one channel and 10 viewers. Paid plans add Restream to up to 30 destinations, Recording Cloud and 24/7 support.