http {
server {
listen 8080;
server_name localhost;
location /on_play {
# set connection secure link
secure_link $arg_st,$arg_e;
secure_link_md5 mysecretkey$arg_app/$arg_name$arg_e;
# bad hash
if ($secure_link = "") {
return 501;
}
# link expired
if ($secure_link = "0") {
return 502;
}
return 200;
}
}
}
rtmp {
server {
listen 1935;
# protected application
application myapp {
live on;
on_play http://localhost:8080/on_play;
}
}
}
With the above configuration you cannot play any stream from myapp application without providing the right secure link.
> ffplay 'rtmp://localhost/myapp/mystream'
ffplay version 1.0.6 Copyright (c) 2003-2013 the FFmpeg developers
...
rtmp://localhost/myapp/mystream: Unknown error occurred
In error.log we have this message
notify: HTTP retcode: 5xx
Now let’s construct valid secure RTMP link. Get current timestamp first and add 1 hour expire time to it.
> date +%s
1370777449
> echo $((1370777449+3600))
1370781049
Then construct the hash (watch config above for key)
> echo -n "mysecretkeymyapp/mystream1370781049" | openssl dgst -md5 -binary |
openssl enc -base64 | tr '+/' '-_' | tr -d '='
Mbjev5ld4mmCN00mwIqD7w
Now we have the hash. It’s easy to construct the valid secure RTMP url.
> ffplay 'rtmp://localhost/myapp/mystream?e=1370781049&st=Mbjev5ld4mmCN00mwIqD7w'
Source: https://rarut.wordpress.com/2013/06/09/secure-links-in-nginx-rtmp/
Nhận xét
Đăng nhận xét