How to set up your own private RTMP server using nginx

All Versions How to set up your own private RTMP server using nginx

Lloyd

New Member
Prefix the command for opening the file with the word "sudo", such as "sudo vi /usr/local/nginx/conf/nginx.conf". That will let you open and edit the file as root.

Is this what it should look like? How do I now save the config edit?

Dodge thank you!

upload_2016-7-12_13-44-39.png
 

dodgepong

Administrator
Community Helper
Yes, that looks right for a basic setup.

To save and quit in vi, first press Escape to make sure you're not in Insert mode, and type :wq and hit enter.
 

alcadel

New Member
Hello !
Thank you very much for the guide. I installed it on a Debian VPS and it works well. I'm using nginx to push my streams on twitch.
However, I'm having trouble with security issues. For now anyone that has my VPS' IP is able to publish streams on my twitch channel. ("allow publish all" by default I guess)

Unfortunatefly, my personnal IP changes almost every day so I cannot use the "allow publish MY_IP" & "deny publish all" feature. Is there any other way to secure the server ? Maybe using a steaming key ?

Thank you very much :)
 

Fenrir

Forum Admin
Hello !
Thank you very much for the guide. I installed it on a Debian VPS and it works well. I'm using nginx to push my streams on twitch.
However, I'm having trouble with security issues. For now anyone that has my VPS' IP is able to publish streams on my twitch channel. ("allow publish all" by default I guess)

Unfortunatefly, my personnal IP changes almost every day so I cannot use the "allow publish MY_IP" & "deny publish all" feature. Is there any other way to secure the server ? Maybe using a steaming key ?

Thank you very much :)

There's a few ways you can do this. The simplest is writing a small on-publish script that will parse a .php or similar script to verify a stream key.

If you do that, you can go live with a stream key along the lines of ChannelName?key=secretkey

Everything after the ? is dropped for playback, but it's passed to the script with on-publish as either GET or PUSH and you can validate the key there, and then 404 if it's invalid.
 

Janle

New Member
Hi,

Does anyone know what is causing this problem? I have looked around a lot on different forums, but I haven't been able to find a solution. When I try to use ffmpeg, it seems that ffmpeg is constantly closing and restarting itself. The same was happening with avconv. I saw that people said it was possibly permission issues and nginx not being able to access ffmpeg, but I tried running nginx under user root and am not seeing anything different. Anyone know what's wrong? I have linked the error.log and nginx.conf. I have edited out my Twitch stream key, but I thought I should tell you just in case.

nginx.conf: http://pastebin.com/zVCNSrXM

error.log: http://pastebin.com/NSjXi6Dm
 

Fenrir

Forum Admin
Hi,

Does anyone know what is causing this problem? I have looked around a lot on different forums, but I haven't been able to find a solution. When I try to use ffmpeg, it seems that ffmpeg is constantly closing and restarting itself. The same was happening with avconv. I saw that people said it was possibly permission issues and nginx not being able to access ffmpeg, but I tried running nginx under user root and am not seeing anything different. Anyone know what's wrong? I have linked the error.log and nginx.conf.

nginx.conf: http://pastebin.com/zVCNSrXM

error.log: http://pastebin.com/NSjXi6Dm

Have you tried running the command manually outside of nginx when a stream is live? You can also try piping the output of the actual command using >> /path/to/some/log.log at the end of your ffmpeg line.

EDIT: also, your path is missing the stream key: rtmp://192.168.1.9/livein/streamkey
 
Last edited:

Janle

New Member
Have you tried running the command manually outside of nginx when a stream is live? You can also try piping the output of the actual command using >> /path/to/some/log.log at the end of your ffmpeg line.

EDIT: also, your path is missing the stream key: rtmp://192.168.1.9/livein/streamkey

Hi, thanks for the reminder on the key! I tried it again, but got the same result. Then I tried executing it out of nginx and it gave me, "RTMP_Connect0, failed to connect socket. 113 (No route to host) rtmp://192.168.1.9/livein/livein: Unknown error occurred." I tried doing the log, but it said permission denied.

EDIT: Sorry, ignore the above, see the post below.
 
Last edited:

Janle

New Member
Have you tried running the command manually outside of nginx when a stream is live? You can also try piping the output of the actual command using >> /path/to/some/log.log at the end of your ffmpeg line.

EDIT: also, your path is missing the stream key: rtmp://192.168.1.9/livein/streamkey

This is what I end up getting when I execute ffmpeg outside of nginx: http://pastebin.com/yeDjKTSN
 

Janle

New Member
So now you have to actually replace STREAM_KEY with your twitch stream key. Make sure you don't post that in any actual configs/logs on here though!

Yeah, I said in my original post that I didn't show the stream key and have edited it out :P.
 
Hi
when sudo systemctl start nginx
the system show this message:
[emerg]: bind() to 0.0.0.0:1935 failed (98: Address already in use)

thank you for your hep
 

Fenrir

Forum Admin
Hi
when sudo systemctl start nginx
the system show this message:
[emerg]: bind() to 0.0.0.0:1935 failed (98: Address already in use)

thank you for your hep

This means that something else on your system is using port 1935. Either nginx is already running, or you need to track down what service is already using that port.
 

Cistron

New Member
For the google VM, I canguess that Google is blocking the traffic. For the local VM, no idea, RPi started working once I recompiled with --debug and made no other changes. Not sure why turning Debug on made a difference, but apparently it does.
I'm having the same issues with a MacBook Air as the RTMP server (installed nginx with the rtmp package via homebrew) and my windows 10 PC with OBS. I can ping the MacBook, but can't connect. Oddly, I can get to the apache2 webserver (port 80) but not the nginx webserver (port 8080) - so something is obviously fishy. *sigh*

I'll give the debug package install a try.
 

Cistron

New Member
Well that didn't do anything. I think it's the windows 10 firewall blocking seemingly all ports. Network utility port scan (from the Mac) didn't show any open ports. At least I can ping it now that I've activated file and printer sharing. Why oh why have you made this so FSM-damn convoluted, Microsoft, why?

Anyone got any recommendations on how best to sort this out?
 

Manoel

New Member
Hello people good night!

I've read this thread from beginning to end but did not find anything to help me.

I need a nginx configuration that works with HLS, tested several here but none worked, did you guys could help me?

I am using CentOS with nginx + rtmp module

If I run only RTMP works normally and can pass but as we know the RTMP does not work for mobile devices so accurate HLS.

Thank you very much!
 

Fenrir

Forum Admin
Hello people good night!

I've read this thread from beginning to end but did not find anything to help me.

I need a nginx configuration that works with HLS, tested several here but none worked, did you guys could help me?

I am using CentOS with nginx + rtmp module

If I run only RTMP works normally and can pass but as we know the RTMP does not work for mobile devices so accurate HLS.

Thank you very much!

Can you share your config that you have tried for HLS? Enabling it should be relatively straightforward if you've found guides on it. Obviously remove any sensitive info first.
 

Hagstrom

New Member
I am not the greatest tech guy so I must ask. Does this set up mean I can have a totally private server to stream to and not pay a 500 a month bill to dacast for the bandwith. Thats what I am interested in is a self hosted live streaming video site from a dedicated server.
I want this for personal use I dont want to be the guy you go to to stream yours know what I mean.

Regards
 

Fenrir

Forum Admin
I am not the greatest tech guy so I must ask. Does this set up mean I can have a totally private server to stream to and not pay a 500 a month bill to dacast for the bandwith. Thats what I am interested in is a self hosted live streaming video site from a dedicated server.
I want this for personal use I dont want to be the guy you go to to stream yours know what I mean.

Regards

Mostly, yes. You would be responsible for providing the server hardware as well as the bandwidth yourself.
 
Top