How to set up your own private RTMP server using nginx

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

jagr_200

Member
How can i protect my server? If somebody knows my server rtmp, he can stream. How can i protect so that nobody can stream except me and cant create a chanelll ?
I use JWPlayer as player.

Change the stream key often. I use JWplayer and embed it on my website. I change it after every stream. That way nobody can stream to my server.
 

sistason

New Member
How can i protect my server? If somebody knows my server rtmp, he can stream. How can i protect so that nobody can stream except me and cant create a chanelll ?
I use JWPlayer as player.
You could use the firewall for that. Windows Firewall or iptables, for Linux. Just tell the firewall, that the port nginx listens on is only allowed for your IP.

A quick announcement that I wrote something to handle the streaming-delay also on the (nginx-)server. So that when OBS crashes or you get disconnected, your whole delayed content is not lost. If anyone is interested in that, check out https://github.com/sistason/rtmp_stream_delayer.
 

deltahf

New Member
Thank you so much for a great guide, this was very helpful!

To clarify, can the same server host multiple RTMP streams simultaneously at the same ingestion URL with multiple streams? Or do I need to define multiple server blocks to handle multiple streams?

For example, let's say I have defined a server as follows:

Code:
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record off;
                }
         }
}

Can I stream to rtmp://rtmp.example.com/live with multiple stream keys, and view the output of each stream independently and simultaneously at rtmp://rtmp.example.com/live/my-stream-key?
 

harakiwi

New Member
Thank you so much for a great guide, this was very helpful!

To clarify, can the same server host multiple RTMP streams simultaneously at the same ingestion URL with multiple streams? Or do I need to define multiple server blocks to handle multiple streams?
[...]
Can I stream to rtmp://rtmp.example.com/live with multiple stream keys, and view the output of each stream independently and simultaneously at rtmp://rtmp.example.com/live/my-stream-key?

Yes multiple people can stream at the same time.
Every new stream needs it's own streamkey
rtmp://x.x.x.x/live/streamguy
rtmp://x.x.x.x/live/streamgirl
rtmp://x.x.x.x/live/lazystream

No config changes.
 

014

Member
You could use the firewall for that. Windows Firewall or iptables, for Linux. Just tell the firewall, that the port nginx listens on is only allowed for your IP.

A quick announcement that I wrote something to handle the streaming-delay also on the (nginx-)server. So that when OBS crashes or you get disconnected, your whole delayed content is not lost. If anyone is interested in that, check out https://github.com/sistason/rtmp_stream_delayer.

Have you tried this? If you have and got it to work, can you share a couple of your iptables script lines? I have tried limiting incoming port 1935 to only my home IP address, but then the video player stayed black for my friend. I was still able to watch the stream. It seems as though one of the following scenarios are happening:
1) Viewers come inbound to port 1935 and therefore it has to be open to the world or many people
2) The stream from nginx to itself (local traffic) is being blocked

The first scenario makes more sense to me. If that is happening, I was thinking of changing the listening port of nginx so I could limit the new listening port to my home IP address. This all leads to my final question: Can OBS push the stream through a port other than 1935?
 

Jack0r

The Helping Squad
http://www.helping-squad.com/nginx-rtmp-secure-your-nginx-server/
Option A: Add the following to your nginx.conf in the rtmp app section
allow publish 192.168.0.0/24;
deny publish all;
allow play all;
deny play all;

With this only addresses using 192.168.0.xxx can send(publish) a stream to nginx, but any IP could play(watch) the stream. You can of course also limit the allow play to an ip range or a single ip address (the one of your friend).
 

WasabiIceCream

New Member
I just set up a Linode server yesterday, and it's been working beautifully.
Just today they sent me a message about an outbound denial of service attack coming from my Linode.
I'm not sure what I should do about this... Any help?
 

WasabiIceCream

New Member
Traffic spiked to ~220Mb/s for ~2 hours.
I'm guessing I should not be trying to push to all Twitch, Instagib, Hitbox, and GamingLive at the same time...
Might have been that little experiment that caused that.
 

hpidriver

New Member
Much thanks to @dodgepong for this guide and @Jack0r for your helpful tips and articles.

I have the basic rtmp streaming server working, however I have run into a problem trying to stream HLS.
I am getting errors from both JWplayer and VLC. From what I found in arut's github I need a crossdomain.xml which I have since created.

JWplayer error is "Cannot load m3u8: crossdomain access denied"

VLC error - http://pastebin.com/mk02BUjm

Please advise :)
 

deltahf

New Member
How can I configure Nginx to start on system boot? I followed this guide (and adjusted the daemon path to /usr/local/nginx/sbin), but I get this error when I actually try to run sudo /etc/init.d/nginx start.

Code:
Starting nginx: start-stop-daemon: unable to start /usr/local/nginx/sbin (Permission denied) nginx.

I've checked the permissions on the file and even changed them to 777, but no luck. Is there a better way?

EDIT: Nevermind! I just figured this out myself. :)

For anyone curious, just edit the /etc/rc.local file and add the following anywhere above the "exit 0" line:

sudo /usr/local/nginx/sbin/nginx

Hope this helps. It might be worth adding this to the main tutorial, because some people using it may not realize they need to restart nginx after every server reboot. I'm shutting down my VPS between streams (so I don't have to pay for it) and this will save me the trouble of having to log back in to the server to restart nginx each time.
 
Last edited:

Bamse

Member
I thought I'd try the new setting "Encode in full range" that can be found in OBS under advanced settings when I reencode the stream to twitch standards on my nginx-server. Does someone know what the appropriate options would be for the exec-line for that? :)
 

Zodiarc

New Member
Don't know it was already answered or not (I`m sorry if it was) . Is there a possibility to check from within java or php code if a stream is live?
 

NeV3rKilL

New Member
I have a problem. I finished the tutorial and my OBS has the greenlight, so it seems streaming, but I cannot open the stream with VLC or SMPLAYER. It seems that load something for a while and then drop and error. smplayer keeps loading forever at very slow speed.

Ok, I found it, This is not working with NVENC, I switched to x264 and worked :D
 
Last edited:

mrgreaper

Member
Hi, i have used your guide before on windows and its been a huge help, the way i used it is i would bounce it to twitch, my co-host would connect to my website(the web browser one this runs) that way he was seeing it in almost realtime (unlike when he had to view it via twitch and that god aweful 30 second delay)

Decided it was time to take the plunge and get a server box after looking about i saw what you said about the raspberry pi, so i got a rasberry pi 2 (the new quad core one).

so heres my question, given the guide is for ubuntu not rasbian, is the steps the same or do i need to change anything?
 

mrgreaper

Member
virtually...any hints on which ones need changing lol
need to refresh the pi so will be trying later just would be good to know
 

dodgepong

Administrator
Community Helper
They are identical in the sense that I can't think of any differences off the top of my head. There should in just following the directions as-is, and if you run into an issue, hopefully it will be pretty clear what the problem is.
 

mrgreaper

Member
i managed to follow the guide, not tested streaming yet, but realised your guide isnt the one i followed before, no jwplayer so no embedded player on local hosted website

found a guide that deals with jplayer in the pages of this thread...only the wget command fails with a 404... somewhat stuck but since its 8am perhaps i should sleep
 

Shlomi

New Member
Hi.
Used this guide to install a nginx server inside a VM, everything works great. My son is streaming to the VM and I can play it using VLC...
Next step I need help with is trying to combine the stream my son is sending inside my OBS setup, so I'll stream our LAN matches to Twitch.
Any help would be appreciated.
 
Top