前言

一句唠叨,工欲善其事,必先利其器,在程序员的工作里,搭建各种环境往往花费过多不必要的时间,这里建议搭建服务端环境时,尽量避开win、macos这种系统,个人比较推崇centos。

操作

下面以centos环境为例(macos安装nginx运气不好会让人崩溃)。

安装nginx及nrm模块

请提前确保已经安装gcc、g++、zlib、pcre、openssl(如果编译nginx过程中仍显示缺少已安装过的库,可以在下方给我留言一起探讨问题)。

  1. cd /usr/local
  2. wget http://nginx.org/download/nginx-1.12.2.tar.gz #下载nginx
  3. tar -xzvf nginx-1.12.2.tar.gz #解压nginx
  4. wget https://codeload.github.com/arut/nginx-rtmp-module/legacy.tar.gz/master #下载nginx-rtmp-module
  5. tar -xzvf arut-nginx-rtmp-module-v1.2.1-0-g791b613.tar.gz #解压nginx-rtmp-module
  6. mv ./arut-nginx-rtmp-module-v1.2.1-0-g791b613 ./NRM #改个名
  7. ./configure --add-module=/usr/local/NRM --prefix=/usr/local/nginx --with-debug
  8. make
  9. make install #至此nginx安装完成
  10. /usr/local/nginx/sbin/nginx #启动nginx
  11. /usr/local/nginx/sbin/nginx -V #查看nginx安装模块信息和版本号

配置nginx.conf


  1. #user nobody;
  2. worker_processes 1;
  3. #error_log logs/error.log;
  4. #error_log logs/error.log notice;
  5. #error_log logs/error.log info;
  6. #pid logs/nginx.pid;
  7. events {
  8. worker_connections 1024;
  9. }
  10. ######################ADD RTMP################
  11. rtmp { #RTMP服务
  12. server {
  13. listen 1935; #//服务端口
  14. chunk_size 4096; #//数据传输块的大小
  15. application vod {
  16. play /opt/video/vod; #//视频文件存放位置,自定义
  17. }
  18. application live { #第一处添加的直播字段
  19. live on;
  20. }
  21. application push{
  22. live on; #开启直播
  23. push rtmp://<自己公网ip,没有可以填localhost本地玩一下>/live; #推流到上面的直播应用
  24. }
  25. }
  26. }
  27. #####################ADD RTMP################
  28. http {
  29. include mime.types;
  30. default_type application/octet-stream;
  31. #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  32. # '$status $body_bytes_sent "$http_referer" '
  33. # '"$http_user_agent" "$http_x_forwarded_for"';
  34. #access_log logs/access.log main;
  35. sendfile on;
  36. #tcp_nopush on;
  37. #keepalive_timeout 0;
  38. keepalive_timeout 65;
  39. #gzip on;
  40. server {
  41. listen 80;
  42. server_name localhost;
  43. #################################################
  44. location /stat { #第二处添加的location字段。
  45. rtmp_stat all;
  46. rtmp_stat_stylesheet stat.xsl;
  47. }
  48. location /stat.xsl { #第二处添加的location字段。
  49. root /usr/local/NRM/; #一定要填对
  50. }
  51. ##################################################
  52. #charset koi8-r;
  53. #access_log logs/host.access.log main;
  54. location / {
  55. root html;
  56. index index.html index.htm;
  57. }
  58. #error_page 404 /404.html;
  59. # redirect server error pages to the static page /50x.html
  60. #
  61. error_page 500 502 503 504 /50x.html;
  62. location = /50x.html {
  63. root html;
  64. }
  65. # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  66. #
  67. #location ~ \.php$ {
  68. # proxy_pass http://127.0.0.1;
  69. #}
  70. # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  71. #
  72. #location ~ \.php$ {
  73. # root html;
  74. # fastcgi_pass 127.0.0.1:9000;
  75. # fastcgi_index index.php;
  76. # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
  77. # include fastcgi_params;
  78. #}
  79. # deny access to .htaccess files, if Apache's document root
  80. # concurs with nginx's one
  81. #
  82. #location ~ /\.ht {
  83. # deny all;
  84. #}
  85. }
  86. # another virtual host using mix of IP-, name-, and port-based configuration
  87. #
  88. #server {
  89. # listen 8000;
  90. # listen somename:8080;
  91. # server_name somename alias another.alias;
  92. # location / {
  93. # root html;
  94. # index index.html index.htm;
  95. # }
  96. #}
  97. # HTTPS server
  98. #
  99. #server {
  100. # listen 443 ssl;
  101. # server_name localhost;
  102. # ssl_certificate cert.pem;
  103. # ssl_certificate_key cert.key;
  104. # ssl_session_cache shared:SSL:1m;
  105. # ssl_session_timeout 5m;
  106. # ssl_ciphers HIGH:!aNULL:!MD5;
  107. # ssl_prefer_server_ciphers on;
  108. # location / {
  109. # root html;
  110. # index index.html index.htm;
  111. # }
  112. #}
  113. }

完成以上步骤后,保存,执行nginx -s reload重新加载。

/stat可以看到如下信息:

推流端配置

下载并安装obs,点击下图设置(这里我觉得该有个马赛克!!)



并填入如下url(换成自己的ip即可)



点击开始推流,进行推流,可以看到/stat有数据的变化信息。

拉流端

这时候可以选用任意一款支持rtmp的播放器,填入rtmp:///live观看直播。

总结

这里的架构虽然比较简单,推流、拉流,中间通过nginx转发,却也给直播入门提供一个清晰的感官上的体验。HAVE FUN!

基于obs+nginx-rtmp-module搭建自己直播的系统的更多相关文章

  1. centos7+nginx+rtmp+ffmpeg搭建流媒体服务器(保存流目录与http目录不要随意配置,否则有权限问题)

    搭建nginx-http-flv-module升级代替rtmp模块,详情:https://github.com/winshining/nginx-http-flv-module/blob/master ...

  2. Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务

    1. 背景 不知不觉笔者来到流媒体部门已经一年半多了,积攒了不少的流媒体知识,但平时工作也比较忙,很少进行总结性的梳理,最近准备花几个周末时间写一个流媒体系列的实践文章,也算是给自己做总结的同时帮助有 ...

  3. (转)Nginx+rtmp+ffmpeg搭建流媒体服务器

    (1)下载第三方扩展模块nginx-rtmp-module # mkdir module && cd module //创建一个存放模块的目录 # wget https://githu ...

  4. 使用 nginx 和 rtmp 插件搭建视频直播和点播服务器

    使用 nginx 和 rtmp 模块 ,可以很容易地搭建一个视频直播和点播服务器出来. 首先,看一下最经典的参考文献: How to set up your own private RTMP serv ...

  5. Nginx+rtmp+ffmpeg 搭建推流服务器

    1. 安装nginx服务器 1.1 clone $ brew tap denji/homebrew-nginx 1.2 安装 $ brew install nginx-full --with-rtmp ...

  6. centos7+nginx+rtmp+ffmpeg搭建流媒体服务器

    1.安装前需要的工具 #net-tool 查本地IP #wget 下载安装包 #unzip 解压zip包 #gcc gcc-c++ perl 编译软件包用 yum install -y net-too ...

  7. Ubuntu中使用Nginx+rtmp搭建流媒体直播服务

    一.背景 本篇文章是继上一篇文章<Ubuntu中使用Nginx+rtmp模块搭建流媒体视频点播服务>文章而写,在上一篇文章中我们搭建了一个点播服务器,在此基础上我们再搭建一个直播服务器, ...

  8. ffmpeg,rtmpdump和nginx rtmp实现录屏,直播和录制

    公司最近在做视频直播的项目,我这里分配到对直播的视频进行录制,录制的方式是通过rtmpdump对rtmp的视频流进行录制 前置的知识 ffmpeg: 用于实现把录屏工具发出的视频和音频流,转换成我们需 ...

  9. Linux-Nginx+rtmp+ffmpeg搭建流媒体服务器

    Nginx+rtmp+ffmpeg搭建流媒体服务器 说明: nginx搭建流媒体服务需要用到 nginx-rtmp-module 模块 具体操作步骤: 安装nginx (1)下载第三方扩展模块ngin ...

随机推荐

  1. EBS _ALL, _TL, _VL, _V,_F,_VL,_A,_AVN and what else

    http://hi.baidu.com/einsteinalbert/item/54579250efc637abadc85705 _ALL, _TL, _VL, _V,_F,_VL,_A,_AVN a ...

  2. 【WP8.1】页面的导航效果

    <Page.Transitions> <TransitionCollection> <NavigationThemeTransition> <CommonNa ...

  3. jxl库介绍

    jxl是个韩国人开发的java中操作excel的库(棒子国思密达) 相对于另一个java excel库poi来说,jxl具有小巧和使用简单等优点. File uploadedFile = new Fi ...

  4. 字符串写入txt文件

    将字符串写入C盘txt文件里 File.AppendAllText(@"C:\" + DateTime.Now.ToString("HHmmss") + &qu ...

  5. Educational Codeforces Round 25 B. Five-In-a-Row

    题目链接:http://codeforces.com/contest/825/problem/B B. Five-In-a-Row time limit per test 1 second memor ...

  6. linux下各个目录里面都装了什么

    文章来源:http://blog.csdn.net/sunstars2009918/article/details/7038772 搞电脑的人总想知道自己的系统里到底有些什么东西,于是我就在Linux ...

  7. windows 安装nexus3

    下载地址 nexus官网下载页面 文件名:nexus-3.3.1-01-win64.zip,解压,cd到bin目录 运行: nexus.exe /run 1 安装成系统服务: nexus.exe /i ...

  8. sqlmap命令详解

    cookie注入:sqlmap.py -u 注入点 --cookie "参数" --tables --level 2 POST登录框注入:sqlmap.py -r 从文件读取数据 ...

  9. ubuntu14.04 安装五笔输入法(fcitx)

    ubuntu 14.04安装完成之后,一打字,默认的ibus一直在显示.解决办法,直接卸载ibus,使用fcitx. fictix拼音有fcitx-pinyin.fcitx-sogoupinyin.f ...

  10. python操作oracle数据库-查询

    python操作oracle数据库-查询 参照文档 http://www.oracle.com/technetwork/cn/articles/dsl/mastering-oracle-python- ...