How to set up your own private RTMP server using nginx

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

nirvanaruns

New Member
i already create my own RTMP (re-stream server) in a raspberry pi 3 b+ but how can i access to the rtmp server from another network?

with the internal IP address works great but i want to stream from another network with the public IP address...

i already use this tutorial: https://obsproject.com/forum/resources/how-to-set-up-your-own-private-rtmp-server-using-nginx.50/

and my code is:
Code:
cat /usr/local/nginx/conf/nginx.conf



#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  streaming;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application channel1 {
                        record off;
                        live on;
                        push rtmp://live-scl.twitch.tv/app/live_000000000_xxxxxxxxxxxxxxxxxxxxxxxxxxx;
                        push rtmp://a.rtmp.youtube.com/live2/xxxxx-xxxx-xxxx-xxxx;
                        push rtmp://live-api.facebook.com:80/rtmp/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx;

                 }
               
                application channel2 {
                        record off;
                        live on;
                        push rtmp://live-scl.twitch.tv/app/live_000000000_yyyyyyyyyyyyyyyyyyyyyyyyyy;
                        push rtmp://a.rtmp.youtube.com/live2/yyyy-yyyy-yyyy-yyyy;
                        push rtmp://live-api.facebook.com:80/rtmp/yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy;
                }
        }
    }

port is open i think:

Code:
root@raspberrypi:/home/pi# sudo netstat -lptu |grep nginx
tcp        0      0 0.0.0.0:1935            0.0.0.0:*               LISTEN      543/nginx: master p
tcp        0      0 0.0.0.0:http            0.0.0.0:*               LISTEN      543/nginx: master p

can anyone help me? thanks a lot
icon_e_smile.gif
(s.o. is raspbian)
 

Tarumes

Member
So, once I have the RTMP and Nginx server set up, how would I make it so that 2 different people in separate locations can stream to it? I am trying to "combine" their streams into a single stream on my computer (via VLC player or something). Then I'm going to use that VLC window as a source in OBS.

But I'm confused about how 2 people streaming to the RTMP at the same time would work. If I do that, and then get the stream to come up on VLC I would imagine that it would only show a single stream? Or maybe it wouldn't work at all?

Streamer 1 set
Server: rtmp://<your_server_ip>/stream1
Streamkey: stream

Streamer 2 set
Server: rtmp://<your_server_ip>/stream2
Streamkey: stream

in vlc
rtmp://<your_server_ip>/stream1/stream
and
rtmp://<your_server_ip>/stream2/stream

Code:
worker_processes  1;

error_log  logs/error.log;

events {
    worker_connections  1024;
}
rtmp_auto_push on;
rtmp_auto_push_reconnect 1s;

rtmp {
    server {
        listen 1935;

        application stream1 {
            live on;
        }
        
        application stream2 {
            live on;
        }
    }
}

http {
    server {
        listen      8080;
        
        location / {
            root html;
        }
        
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }

        location /stat.xsl {
            root html;
        }
        location /control {
            rtmp_control all;
        }
    }
}
 

georgezilla

New Member
" ... But when I try to connect VLC to the NGINX server in order to view my desktop I got the "unable to open/access address". ... "

When you try to connect to the rtmp server with VLC, are you .....

Media --- Open Network Stream

and entering the complete URL?

rtmp:// (whatever address you are connecting to ) / ( whatever you named it ) / ( stream key )

Example:

rtmp://127.0.0.1/live/test ( Is what mine is )

It needs to be EXACTLY the same in both VLC and OBS.

I only use my rtmp server to "test" my settings ( audio, ect. ), BEFORE I stream to the internet. That way I know that it IS working correctly. And I know that it is, so if people whine, I can tell them that it is on their end and not on mine. ( Ok, sometimes I actually have my tablet connected to it when I stream, so that I can monitor it live. But not often. )

My question to you is ....

Exactly why you want to have/use your own rtmp server?[/QUOTE]
 
Last edited:

georgezilla

New Member
" ... However when entering that same address into the custom OBS settings it tells me it failed to connect and the error log for OBS claims that the server is offline. ... "

I am only asking questions, making suggestions. I am not trying to be insulting or condescending.

When you connect to the nginx "web server" you are connecting to it via http://xxx.xxx.xxx.xxx.

When you want to connect to your "stream server" you need to connect via rtmp://xxx.xxx.xxx.xxx with something like VLC.

When I connect to mine the URL is ....

rtmp://192.168.0.147/live/test

"live" being the what I've named the stream, and "test" being the stream key.

And they must be exactly the same in OBS and VLC.

Also are you sure that you actually streaming in OBS? Sometimes I get ahead of myself and try to view my stream, before I've actually started to stream.
 

georgezilla

New Member
The only thing I am struggling with is connecting out of Network, I am pretty knowledge/capable with most hardware software stuff, but don't know jack about networking... Is it a firewall issue?

Could be a "firewall issue" or a router issue. You may need to do some "forwarding" ( port or otherwise )

Or it could be a dynamic-IP issue.

I'm not a network guy by any stretch of the imagination.

But at least I tried.
 

Mark Weiss

Member
I'm still trying to figure out how to solve the 30 second time limit on live streaming. Seems browser-related, as I can refresh the page to view another 30 seconds, but it doesn't continue automatically they way live streams from Youtube an Twitch do.
 

Mark Weiss

Member
My Twitch stream stopped working on mobile devices this morning. I have 27 days to figure out how to stream from my own server. Can't rely on corporate streaming services. One day they work, next day they don't.
 

ageofglitch

New Member
Hi guys I have a really wild question:
It's possible use variables inside nginx.conf? I want to use the next url to stream:

rtmp://server.com/live/stream_key

so I can catch t he data something like:

rtmp{
server{
application live{
if($name = 'stream_key'){
set $twitch "twitch_key";
}
if($name = 'stream_key1'){
set $twitch "twitch_key";
}

push rtmp://twitch_ingest/$twitch;

}
}
}

The main reason behind this it's because I don't want to use different urls for each stream to push the re-streams to other sites.
 
Where's a guide how to setup RTMP on Windows? I have 2 brand new GoPro Hero 7 Black. They can stream right from the device to certain platforms.. but for Twitch I need RTMP.

I'd like to stream live from my friends arcade. I'd like to figure out how to put the two camera streams side by side, on overlay of classic arcade graphics, and put up a logo of the business, with his address and hours.

Any help is greatly appreciated.
 

Ennorath

New Member
Hello, I want to do server and for this will be more convenient to use nginx as base of server. I installed at first nginx by commands sudo apt-get install nginx. How i can add "dev.zip" to here? (now nginx folder located in folder "/etc")
 

dfrye

New Member
Thank you very much for the excellent guide. I have used it for month withour any problems on a vps to simultanously stream to facebook and YouTube. Now facebook is changing to only accept SSL-connections via RTMPS on Port 443. If I edit nginx.conf by adding "push rtmps://live-api-s.facebook.com:443/rtmps..." I cannot start the server. Can anybody help me????
 

Tarumes

Member
Thank you very much for the excellent guide. I have used it for month withour any problems on a vps to simultanously stream to facebook and YouTube. Now facebook is changing to only accept SSL-connections via RTMPS on Port 443. If I edit nginx.conf by adding "push rtmps://live-api-s.facebook.com:443/rtmps..." I cannot start the server. Can anybody help me????

nginx rtmp dont support rtmps
 

Token_ZA

New Member
HI guys, i have read through all the manuals and googled for days, and i need your help, i want to add multiple users (streaming in SA is a big problem), and i cant seem to do it, when my friend and i stream, all we end up doing is cutting each other off and for some reason stream to HIS twitch account, no matter what happens.

Please someone help me!!!
 

Tarumes

Member
HI guys, i have read through all the manuals and googled for days, and i need your help, i want to add multiple users (streaming in SA is a big problem), and i cant seem to do it, when my friend and i stream, all we end up doing is cutting each other off and for some reason stream to HIS twitch account, no matter what happens.

Please someone help me!!!
post your config but censore stream key if you set a push
 

kpcenti

New Member
This feels really silly, but what Windows Binary am I suppose to use ? The link lists more than a dozen of binaries to use
 

kpcenti

New Member
This one
https://github.com/illuspas/nginx-rtmp-win32
or
rtmp, 1.7.12.1 is the last free version with rtmp

but all "exec" options are not aviable on windows
on linux ubuntu its easy to install

Code:
sudo apt-get update
sudo apt-get install nginx libnginx-mod-rtmp
sudo nano /etc/nginx/nginx.conf
make your config and have fun
Code:
sudo service nginx restart
Thanks so much! The Guide doesn't mention that github link or does it mention which last version has rtmp for free
 

Tarumes

Member
Thanks so much! The Guide doesn't mention that github link or does it mention which last version has rtmp for free
the link to 1.7.12.1 is the last free build for windows without paid subscription from nginx-win.ecsds
the link to github is a chinese person who build it for free every few month to stay at newest nginx version
 

kpcenti

New Member
I'm wanting to record the video that's being sent to the server. I have my conf set up like this now
Code:
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record all;
                        record_path /Recordings;
                        record_suffix -%F.flv;
                        record_unique on;

                }
        }
}

Sending video to it fails now. Am i writing the configs wrong?
 

Tarumes

Member
I'm wanting to record the video that's being sent to the server. I have my conf set up like this now
Code:
rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application live {
                        live on;
                        record all;
                        record_path /Recordings;
                        record_suffix -%F.flv;
                        record_unique on;

                }
        }
}

Sending video to it fails now. Am i writing the configs wrong?

Code:
rtmp {
    server {
        listen 1935;
        
        application view {
            live on;
            recorder all {
                record all;
                record_path html; #this folder should exist before streaming to your server
                record_lock on;
                record_unique on;
            }
        }
    }
}
 
Top