Nginx基础知识之————多模块(非覆盖安装、RTMP在线人数实例安装测试)
说明:
已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么弄呢?
具体:这里以安装第三方nginx-rtmp-module和nginx-accesskey-2.0.3模块为例,nginx的模块是需要重新编译nginx,而不是像apache一样配置文件引用.so
1. 下载第三方扩展模块nginx-rtmp-module
sudo git clone https://github.com/arut/nginx-rtmp-module.git
2. 下载第三方扩展模块nginx-accesskey-2.0.3
http://www.filewatcher.com/m/nginx-accesskey-2.0.3.tar.gz.2632-0.html 下载后解压即可
tar.gz 这种格式是我使用得最多的压缩格式。它在压缩时不会占用太多CPU的,而且可以得到一个非常理想的压缩率。使用下面这种格式去压缩一个目录:
# tar -zcvf archive_name.tar.gz directory_to_compress
解压缩:
# tar -zxvf archive_name.tar.gz
3、最后下载的结果如下所示,git上下载的是不需用解压的,nginx-accesskey-2.0.3 下载下来需要解压的
4.cp nginx-accesskey-2.0.3 到Nginx 安装目录下去 nginx-1.8.1
修改 nginx-accesskey-2.0.3 文件下面的配置文件
vim nginx-accesskey-2.0.3/config
#修改$HTTP_ACCESSKEY_MODULE为ngx_http_accesskey_module
USE_MD5=YES
USE_SHA1=YES
ngx_addon_name=ngx_http_accesskey_module
HTTP_MODULES="$HTTP_MODULES ngx_http_accesskey_module"
NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_accesskey_module.c"
5、提示安装错误:
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.
大概意思是:HTTP重写模块需要PCRE库。您可以使用--without-http_rewrite_module禁用模块选项,或将PCRE库安装到系统中,或构建PCRE库通过使用--with-pcre = <path>选项从源与nginx静态。
解决办法:
需要安装一下两个库文件:(nginx pcre 安装)
sudo apt-get install libpcre3 libpcre3-dev
apt-get install openssl libssl-dev
apt-get install git
6、在Nginx安装目录下面配置文件
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module --add-module=./nginx-accesskey-2.0.3 --add-module=../nginx-rtmp-module/
注意:安装时候的两个模块是在不同的目录下面的,所以在配置文件的时候一定要记住这个文件路径必须的合适,否则安装不成功,提示一下错误:
7、编译:
make
#不要make install,否则就是覆盖安装
8、 替换nginx二进制文件:
root@iZ231gvwxe7Z:/home/www/nginx-1.8.1# cd objs/
root@iZ231gvwxe7Z:/home/www/nginx-1.8.1/objs# ls
addon autoconf.err Makefile nginx nginx.8 ngx_auto_config.h ngx_auto_headers.h ngx_modules.c ngx_modules.o src
root@iZ231gvwxe7Z:/home/www/nginx-1.8.1/objs# cp nginx /usr/local/nginx/sbin/nginx
9、 查看已经安装好的模块和重启Nginx:
www@iZ231gvwxe7Z:/tmp/hls$ /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.8.
built by gcc 4.8. (Ubuntu 4.8.-19ubuntu1)
built with OpenSSL 1.0.1f Jan
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
--with-http_ssl_module --with-http_realip_module
--add-module=./nginx-accesskey-2.0.3
--add-module=../nginx-rtmp-module/
配置文件:
user www www;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/warn.log warn; #pid logs/nginx.pid; events {
worker_connections 65525;
} 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 localhost; #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;
}
}
} rtmp {
server {
listen 1935;
chunk_size 4096; application live {
live on;
record off;
exec /home/www/bin/deviceToUrlStreamName.sh $name;
exec_kill_signal term; }
application live360p {
live on;
record off;
}
}
}
10、 重启Nginx:
service nginx restart
11.增加一个RTMP在线统计人数模块:
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_ssl_module --with-http_flv_module --with-http_perl_module --with-http_xslt_module --add-module=../nginx-rtmp-module/
配置 --with-http_xslt_module 时提示 the HTTP XSLT module requires the libxml2/libxslt libraries
提示错误:./configure: error: the HTTP XSLT module requires the libxml2/libxslt
sudo apt-get install libxml2 libxml2-dev libxslt-dev
sudo apt-get install libgd2-xpm libgd2-xpm-dev
修改 nginx 配置文件,增加以下两个代码:
location /stat {
rtmp_stat all;
allow 127.0.0.1;
} location /nclients {
proxy_pass http://127.0.0.1/stat;
xslt_stylesheet /www/nclients.xsl app='$arg_app' name='$arg_name';
add_header Refresh "3; $request_uri";
}
创建一个简单地 xls 表格文件 nclients.xsl 用于提取观看当前频道的用户数量,编辑其内容如下:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html"/> <xsl:param name="app"/>
<xsl:param name="name"/> <xsl:template match="/">
<xsl:value-of select="count(//application[name=$app]/live/stream[name=$name]/client[not(publishing) and flashver])"/>
</xsl:template> </xsl:stylesheet>
使用HTTP请求http://myserver.com/nclients?app=myapp&name=mystream获取流订阅者的数量。 在浏览器或iframe中打开时,此编号将每3秒自动刷新一次。
重启Nginx服务:
root@iZ231gvwxe7Z:/home/www/nginx-1.8.1/objs# service nginx restart
* Stopping Nginx Server... [fail]
* Starting Nginx Server... [ OK ]
root@iZ231gvwxe7Z:/home/www/nginx-1.8.1/objs#
使用OBS推流该Nginx服务器的RTMP模块既可以
例如我测试的结果:
使用VLC播放该流
测试在线观看人数结果(只有我一个人播放的,就是一个人哦!):
参考文献:
https://github.com/arut/nginx-rtmp-module/wiki/Getting-number-of-subscribers
http://blog.csdn.net/defonds/article/details/9065591
http://www.cnblogs.com/terrysun/archive/2012/11/22/2782472.html
如何升级Nginx到最新稳定版:http://www.cnblogs.com/terrysun/archive/2012/11/22/2782472.html
Nginx基础知识之————多模块(非覆盖安装、RTMP在线人数实例安装测试)的更多相关文章
- 【推荐】Nginx基础知识之————多模块(非覆盖安装、RTMP在线人数实例安装测试)
说明:已经安装好的nginx,需要添加一个未被编译安装的模块,需要怎么弄呢? 具体:这里以安装第三方nginx-rtmp-module和nginx-accesskey-2.0.3模块为例,nginx的 ...
- nginx添加模块 (非覆盖安装)
nginx添加模块(非覆盖安装) 原已经安装好的nginx,现在需要添加一个未被编译安装的模块: 查看原来编译时都带了哪些参数# /usr/local/nginx/sbin/nginx -V ngin ...
- day63:Linux:nginx基础知识&nginx基础模块
目录 1.nginx基础知识 1.1 什么是nginx 1.2 nginx应用场景 1.3 nginx组成结构 1.4 nginx安装部署 1.5 nginx目录结构 1.6 nginx配置文件 1. ...
- Nginx基础知识介绍
Nginx基础知识介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.Nginx概述 Nginx是免费的.开源的.高性能的HTTP和正向/反向代理服务器.邮件代理服务器.以及T ...
- Nginx基础知识之————RTMP模块中的中HLS专题(翻译文档)
一.在Nginx配置文件的RTMP模块中配置hls hls_key_path /tmp/hlskeys; 提示错误信息: nginx: [emerg] the same path name " ...
- Nginx基础知识之————RTMP模块专题(实践文档)
on_publish 语法:on_publish url上下文:rtmp, server, application描述:这个可以设置为一个API接口(GET方式接受所有参数),会给这个API接口返回8 ...
- nginx基础知识总结
1.nginx的工作模式 master/worker工作模式: 一个master进程: 负载加载和分析配置文件.管理worker进程.平滑重启升级等. 一个或多个worker进程 处理并响应用户请求 ...
- Nginx 基础知识学习
资料 基础 掘金-前端开发者必备的Nginx知识 介绍的比较综合,正向代理反向代理的区别.负载均衡等知识,都有介绍 静默虚空-Nginx 简易教程 博客园上的一篇推荐文章 简书-全面了解Nginx到底 ...
- Nginx基础知识之————Nginx 环境的搭建?
本课时主要给大家讲解如何在 Linux 系统下搭建 Nginx 和 Nginx 搭建过程中常见问题的知识,并结合实例让学员掌握 Nginx 环境的搭建. 下载解压: 安装gcc-c++ 从新配置文件: ...
随机推荐
- jQuery 文档操作方法(w3school)
这些方法对于 XML 文档和 HTML 文档均是适用的,除了:html(). 方法 描述 addClass() 向匹配的元素添加指定的类名. after() 在匹配的元素之后插入内容. append( ...
- PHP处理CSV表格文件的常用操作方法是怎么样呢
php来说,fgetcsv读入csv表格,返回一个数组,然后foreach输出成HTML的<table>,这步操作几行代码就能实现,非常简单.工作量主要还在于浏览器前端,建议你用jQuer ...
- PHP程序员如何突破成长瓶颈
PHP因为简单而使用,但不能因为它的简单而限制我们成长!文章给PHP工程师突破成长瓶颈提了一些建议,希望PHPer能够突破自己,有更好的发展. AD: 作为Web开发中应用最广泛的语言之一,PHP有着 ...
- ecshop发票不能使用出现flow.php on line 723等报错
最模板给客户ecshop网站做编码转换出现个问题,网站在点结算页面出现Warning: Invalid argument supplied for foreach flow.php on line 7 ...
- GPS定位原理
多分钟吧(有人认为美国对其本土覆盖的GPS信号实行不同码率因此纯GPS定位也会很快,谁有美国朋友不妨让他拔卡试试)!因为美版机型其GPS模块的数据处理软件部分与欧版机型是不同的,欧版机型的数据处理软件 ...
- YTU 3022: 完全二叉树(1)
原文链接:https://www.dreamwings.cn/ytu3022/2595.html 3022: 完全二叉树(1) 时间限制: 1 Sec 内存限制: 128 MB 提交: 26 解决 ...
- HASH表原理(装)
HASH表原理 大家都知道,在所有的线性数据结构中,数组的定位速度最快,因为它可通过数组下标直接定位到相应的数组空间,就不需要一个个查找.而哈希表就是利用数组这个能够快速定位数据的结构解决以上的问题的 ...
- 实现Fragment的切换和ViewPager自动循环设置切换时间
1.FragmentActivity与Fragment之间的用法 2.实现ViewPager自动轮换,设置移动的时间 通过反射获取mScrooler这个对象: Field mScroller; mSc ...
- Unity脚本在层级面板中的执行顺序测试2
上一篇测试了生成顺序对执行顺序的影响,链接:LINK 执行顺序测试3: LINK 这篇主要测试一下Awake,OnEnable,Start三个常用消息的循环顺序 1.测试消息循环顺序 先上一个最简单的 ...
- python中给for循环增加索引
for index, item in enumerate(Foo()): print "index: ", index, " item: ",item 用enu ...