With this practical guide, you will create a server that forward the received stream to services like YouTube ad Facebook, as a self-hosted alternatives to services like Restream.
If you want to dive deeper on a multistream setup, look at the article on my blog.
Initial server setup
- Follow the guide at Initial VPS setup
Install required packages
- Install nginx:
$ apt-get install nginx
- Install the RTMP module:
$ apt-get install libnginx-mod-rtmp
- Update the firewall and check if the setup is OK:
$ ufw allow 1935 $ ufw status verbose
- Reboot
Setup NGINX
- Edit NGINX config:
$ nano /etc/nginx/nginx.conf
- At the end of the file add the following:
rtmp {
server {
listen 1935;
chunk_size 4096;
application live {
live on;
record off;
push rtmp://a.rtmp.youtube.com/live2/<your-youtube-key>;
push rtmp://127.0.0.1:19350/rtmp/<your-fb-persisten-key>;
}
}
}
- Restart NGINX
$ systemctl restart nginx
(Only if you use Facebook) Setup Stunnel
- Install Stunnell:
$ apt-get install stunnel4
- Enable Stunell auto boot:
$ nano /etc/default/stunnel4
- Change ENABLE to 1:
ENABLE=1
- Edit Stunnel configuration:
$ nano /etc/stunnel/stunnel.conf
- Enter the following config:
pid = /var/run/stunnel4/stunnel.pid
output = /var/log/stunnel4/stunnel.log
setuid = stunnel4
setgid = stunnel4
# https://www.stunnel.org/faq.html
#socket = r:TCP_NODELAY=1
#socket = l:TCP_NODELAY=1
debug = 4
[fb-live]
client = yes
accept = 127.0.0.1:19350
connect = live-api-s.facebook.com:443
verifyChain = no
- Enable Stunell on boot:
$ systemctl enable stunnel4.service
- Restart Stunnell
$ systemctl restart stunnel4.service
Ready to test!
Test setup with OBS.
OBS Stream configuration
Go to SettingsยปStream
Service: Custom
Server: rtmp://<ngnix server IP address>/live
Stream Key: test
Setup scripts
I have created some scripts to execute the setup automatically. You can find them here with all the instructions. I suggest you to execute the setup manually the first time, to understand better what is going on.
Reference
- https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/
- https://www.hostslim.eu/blog/hostslim/using-a-vps-for-streaming/
- https://github.com/arut/nginx-rtmp-module/issues/url
- https://sites.google.com/view/facebook-rtmp-to-rtmps/home
- https://dev.to/lax/rtmps-relay-with-stunnel-12d3