Step‑by‑Step Guide to Deploy SRS for RTMP‑to‑WebRTC with Docker and Nginx
This tutorial walks through deploying SRS in Docker, persisting its configuration, mapping required ports, customizing the rtmp2rtc.conf file, and optionally exposing the WebRTC signaling service via Nginx with HTTPS, providing all commands and configuration snippets needed for a successful setup.
Introduction
The author needed to deploy DJI's SRS service on the cloud to convert RTMP video streams to WebRTC, configure HTTPS, and resolve numerous errors encountered during setup. This guide records the complete deployment process for future reference.
Environment Preparation
Docker is used for deployment, and configuration files are persisted to avoid re‑configuration. The required Docker run command maps the container ports to the host.
docker run --name srs_dji -it -p 7935:7935 -p 1985:1985 -p 8899:8899 -p 8000:8000/udp registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 ./objs/srs -c conf/rtmp2rtc.confThe ports used are:
7935 – RTMP protocol port
1985 – WebRTC signaling service port
8899 – SRS web console port
8000 – WebRTC video stream service interface
If the deployment is on a public network, these ports must be opened, and ports 1985 and 8899 can be mapped through Nginx.
Persisting Configuration Files
SRS stores its configuration under /usr/local/srs/conf/. Copy these files to a local directory to use as a volume mount:
docker cp srs_dji:/usr/local/srs/conf/ ./srs_config/This copies the running container’s configuration into ./srs_config/ on the host.
Restarting the Service with Persistent Config
docker run --name srs_dji -it -p 7935:7935 -p 1985:1985 -p 8899:8899 -p 8000:8000/udp -v $(pwd)/srs_config/conf:/usr/local/srs/conf registry.cn-hangzhou.aliyuncs.com/ossrs/srs:5 ./objs/srs -c conf/rtmp2rtc.confThe -v flag mounts the local configuration directory into the container, ensuring that subsequent restarts use the edited files.
File Configuration (rtmp2rtc.conf)
# RTMP video stream port
listen 7935;
max_connections 1000;
daemon off;
srs_log_tank console;
http_server {
enabled on;
# Management page port
listen 8899;
dir ./objs/nginx/html;
}
http_api {
enabled on;
# RTC signaling service port
listen 1985;
}
stats {
network 0;
}
rtc_server {
enabled on;
# RTC service port
listen 8000;
# UDP port
candidate 127.0.0.1;
}
vhost __defaultVhost__ {
rtc {
enabled on;
rtmp_to_rtc on;
rtc_to_rtmp on;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
}
tcp_nodelay on;
min_latency on;
play {
gop_cache off;
queue_length 10;
mw_latency 100;
}
publish {
mr off;
}
}Edit /srs_config/config/rtmp2rtc.conf with the above settings, ensuring the ports match those exposed in the Docker command, then restart the container.
Accessing the Service
Open a browser and navigate to http://{YOUR_IP}:8899 to see the SRS web console, confirming that the service is running. You can then follow streaming tutorials to test the RTMP‑to‑WebRTC conversion.
Nginx Mapping for Public HTTPS Access
If the service must be reachable from the public internet, expose the WebRTC signaling port via HTTPS using Nginx:
server {
listen 8000 ssl;
server_name your_domain;
# SSL certificate paths (replace with actual files)
ssl_certificate /root/ssl/certificate.pem;
ssl_certificate_key /root/ssl/certificate.key;
# SSL optimizations
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers 'ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384';
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# Handle OPTIONS preflight requests
location / {
proxy_pass http://127.0.0.1:1985;
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_connect_timeout 60s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
}This configuration forwards HTTPS traffic on port 8000 to the internal WebRTC signaling service running on port 1985.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Dunmao Tech Hub
Sharing selected technical articles synced from CSDN. Follow us on CSDN: Dunmao.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
