Skip to content

Instantly share code, notes, and snippets.

@pablote
Last active September 17, 2020 20:06
Show Gist options
  • Save pablote/98940229a4970df6d555 to your computer and use it in GitHub Desktop.
Save pablote/98940229a4970df6d555 to your computer and use it in GitHub Desktop.
Install nginx, nginx-rtmp-module and a nodejs app that receives callbacks in a test VM
#!/bin/bash -x
export nginx_version=1.9.9
# get latest rtmp mod
mkdir /usr/local/src
cd /usr/local/src
git clone git://github.com/arut/nginx-rtmp-module.git
# get nginx
wget http://nginx.org/download/nginx-${nginx_version}.tar.gz
tar xzf nginx-${nginx_version}.tar.gz
rm -rf nginx-${nginx_version}.tar.gz
cd nginx-${nginx_version}
./configure --add-module=/usr/local/src/nginx-rtmp-module --with-http_ssl_module
make
make install
cp /usr/local/src/nginx-rtmp-module/stat.xsl /usr/local/nginx
chmod uga+rw /usr/local/nginx/stat.xsl
# backup config
cp /usr/local/nginx/conf/nginx.conf /usr/local/nginx/conf/nginx.conf.backup
# new config
cat > /usr/local/nginx/conf/nginx.conf << "EOF"
#user nobody;
worker_processes 1;
error_log logs/error.log debug;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 8080;
server_name localhost;
# rtmp stat
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root /usr/local/nginx/;
}
# rtmp control
location /control {
rtmp_control all;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
rtmp {
server {
listen 1935;
chunk_size 4096;
ping 30s;
on_connect http://localhost:8100/on_connect;
on_play http://localhost:8100/on_play;
on_publish http://localhost:8100/on_publish;
on_done http://localhost:8100/on_done;
on_play_done http://localhost:8100/on_play_done;
on_publish_done http://localhost:8100/on_publish_done;
on_record_done http://localhost:8100/on_record_done;
on_update http://localhost:8100/on_update;
application dev_live {
live on;
record all manual;
record_path /tmp/;
record_unique on;
record_notify on;
}
}
}
EOF
# setup node.js app that receives callbacks
curl https://raw.githubusercontent.com/creationix/nvm/v0.30.2/install.sh | bash
source ~/.bashrc # this is optional, restaring the terminal is another option
nvm install node
cat > ~/server.js << "EOF"
var http = require('http');
var port = 8100;
http.createServer(function (req, res) {
console.log(req.url);
req.pipe(process.stdout);
req.on('end', function () {
console.log('\n----');
});
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end();
}).listen(port, function () {
console.log('Server running at ' + port);
});
EOF
node ~/server.js
# stop firewall
systemctl stop firewalld
systemctl disable firewalld
# start nginx
/usr/local/nginx/sbin/nginx
# stop nginx
#/usr/local/nginx/sbin/nginx -s quit
# stream video file to nginx
#ffmpeg -re -i test.mp4 -c copy -f flv rtmp://192.168.207.11/dev_publish/lv_12345
# play stream
##ffplay rtmp://192.168.207.11/dev_live/lv_12345
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment