开始有这个想法是因为看到斗鱼的nginx-rtmp
(好像是这个吧)而感到兴趣因此想自己搭建一个玩玩有一段时间了,但是之前由于懒一直没有动只是浏览一下其他大佬发的教程而已。这不在几天前把一个包年包月的阿里云1Mbps升级成按量计费的100Mbps后本也没有想法的,这不……
昨晚就毅然决然的把Windows系统进行了重装,但是开始好像走了很多弯路甚至可能已经搭建好了只是在推流的时候地址不会填而导致提示推流地址错误之类的只能再次重装。最后搭建可以(填对了推流地址)终于能推流了,但是在播放时老是提示无法打开,就在刚刚才知道端口不是和推流一个端口。????本来准备在昨晚一起测试推流和观看的但是到了断网时间了是一直用着热点折腾搭建和推流测试的。
虽然现在网络上教程千千万万,但是我还是重新造轮子重复记录一下吧~~~
一、Nginx
安装nginx的依赖库
1 2 3 4 5 | sudo apt-get update sudo apt-get install libpcre3 libpcre3-dev sudo apt-get install openssl libssl-dev |
下载nginx
下载rtmp的module(由于我没有git)
1 2 3 |
解压
1 | tar -xzvf nginx-1.11.3.tar.gz |
进入目录
1 | cd nginx-1.11.3 |
编译安装
1 2 3 | ./configure --add-module=../nginx-rtmp-module make make install |
运行Nginx
1 2 | cd /usr/local/nginx ./sbin/nginx |
打开IP,如果出现Welcome to nginx!
默认也代表成功。
修改配置文件nginx.conf(/usr/local/nginx/conf)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #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 8080; server_name localhost; # This URL provides RTMP statistics in XML location /stat { rtmp_stat all; # Use this stylesheet to view XML as web page # in browser rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # XML stylesheet to view RTMP stats. # Copy stat.xsl wherever you want # and put the full directory path here #root /usr/local/nginx/html/; root /root/nginx-rtmp-module/; } location /hls { # Serve HLS fragments types { application/vnd.apple.mpegurl m3u8; video/mp2t ts; } root /home; add_header Cache-Control no-cache; } } } #尾部加入 rtmp { server { listen 1935; chunk_size 4000; # TV mode: one publisher, many subscribers application mylive { # enable live streaming live on; # record first 200M of stream record all; record_path /home/live_record; record_max_size 200M; hls on; hls_path /home/hls; hls_fragment 1s; hls_playlist_length 5; allow play all; #on_publish 'http://when start publish live call this url'; #on_done 'http://when live stop call this url'; } } } |
重启使配置文件生效
1 | ./sbin/nginx -s reload |
推流地址: rtmp://服务器ip/mylive/xxxxx
播放地址: rtmp://服务器ip/mylive/xxxxx
hls地址: http://服务器ip:8080/hls/xxxxx.m3u8
状态查看地址:http://服务器ip:8080/stat
但是我的不知道为什么不能查看状态,显示空白也。
我一开始是使用直播姬推流的,地址:rtmp://192.168.1.1:1935/mylive
房间码:cyzwb
后来换了OBS,url:rtmp://192.168.1.1:1935/mylive
流名称:cyzwb
观看地址:http://192.168.1.1:8080/hls/cyzwb.m3u8
由于是按量计费的所以即将”跑路“应该是换限制小鸡来玩或者不玩了,不过还打算测试加速直播的自建CDN这个可能又是不知道多少个日夜的事了…
参考:
http://www.jianshu.com/p/3c99f4435afa
http://blog.csdn.net/O0mm0O/article/details/73896384
超越自我吧
2017年12月21日
Why not red5??
学习到了,貌似您现在有搭建了red5的测试?不过red5基于java?不知道那个占用比较少了。