首页 » 网站推广 » phpsmtpmodule技巧_Nginx 动态编译加载第三方流媒体做事模块NginxRTMPModule

phpsmtpmodule技巧_Nginx 动态编译加载第三方流媒体做事模块NginxRTMPModule

访客 2024-11-24 0

扫一扫用手机浏览

文章目录 [+]

通过帮助命令./configure --help | grep dynamic 查看是否支持动态加载模块

~/build/openresty-1.19.3.1$ ./configure --help | grep dynamic --with-http_xslt_module=dynamic enable dynamic ngx_http_xslt_module --with-http_image_filter_module=dynamic enable dynamic ngx_http_image_filter_module --with-http_geoip_module=dynamic enable dynamic ngx_http_geoip_module --with-http_perl_module=dynamic enable dynamic ngx_http_perl_module --with-mail=dynamic enable dynamic POP3/IMAP4/SMTP proxy module --with-stream=dynamic enable dynamic TCP/UDP proxy module --with-stream_geoip_module=dynamic enable dynamic ngx_stream_geoip_module --add-dynamic-module=PATH enable dynamic external module --with-compat dynamic modules compatibility

如上可看出官方支持9个动态模块编译,须要增加第三方模块,利用参数--add-dynamic-module=即可。

phpsmtpmodule技巧_Nginx 动态编译加载第三方流媒体做事模块NginxRTMPModule

动态模块概述可以加载到NGINX中的模块是用C编写的获取匹配的NGINX开源版本获取模块源,并在必要时变动模块的配置文件利用configure命令的-‌-add-dynamic-module参数针对NGINX开源版本构建动态模块将天生的动态模块(.so文件)加载到NGINX中(modules目录下),并像利用内置模块一样利用它动态模块语法命令:load_moduleDefault: —高下文配置段: main解释:版本必须>=1.9.11实例:load_module modules/ngx_mail_module.so;编译动态模块

这里安装基于Nginx的流媒体做事器:nginx-rtmp-module 模块

phpsmtpmodule技巧_Nginx 动态编译加载第三方流媒体做事模块NginxRTMPModule
(图片来自网络侵删)

项目地址:https://github.com/arut/nginx-rtmp-module

下载 OpenResty

OpenResty® 是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。
用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 运用、Web 做事和动态网关。

// 下载wget https://openresty.org/download/openresty-1.19.3.1.tar.gz// 解压tar -zxvf openresty-1.19.3.1.tar.gz

下载 nginx-rtmp-module

git clone https://github.com/arut/nginx-rtmp-module.git

下载模块路径地址为:/home/www/build/nginx-rtmp-module

编译

进入 OpenResty 目录

cd openresty-1.19.3.1

编译

./configure --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -O3' \--with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib --with-pcre-jit \--with-stream --with-stream_ssl_module --with-stream=dynamic --with-file-aio \--with-threads --with-http_v2_module --with-http_realip_module \--with-http_mp4_module --with-http_gzip_static_module --with-http_ssl_module \--with-http_stub_status_module --with-http_xslt_module \--with-openssl-opt='-g enable-tlsext' --with-stream \--with-stream_ssl_preread_module \--with-compat --add-dynamic-module=/home/www/build/nginx-rtmp-module// 编译make

添加 --with-compat 选项,天生可加载模块的 Nginx 可实行文件

把稳:这里不要实行make install 命令,否则会覆盖已安装的Nginx二进制文件,我们这里是动态加载只须要编译模块天生第三方模块.so文件就行了。

复制模块到指定目录

将模块库ngx_rtmp_module.so文件复制到 /usr/local/openresty/nginx/modules

cp /home/www/build/openresty-1.19.3.1/build/nginx-1.19.3/objs/ngx_rtmp_module.so /usr/local/openresty/nginx/modules/加载模块

要将模块加载到Nginx,请将load_module指令添加到nginx.conf主配置文件的主高下文中。

load_module modules/ngx_rtmp_module.so;

nginx.conf主配置文件参考

user tinywan;worker_processes auto;// 其他配置...load_module modules/ngx_rtmp_module.so;// 其他配置...利用模块

新增流媒体做事器配置

rtmp { server { listen 1935; chunk_size 4000; drop_idle_publisher 10s; idle_streams off; application live { live on; } application hls { live on; hls on; hls_path /tmp/hls; } # MPEG-DASH is similar to HLS application dash { live on; dash on; dash_path /tmp/dash; } }}

把稳:该配置须要和HTTP高下文并列,而不是放在HTTP模块里面

检测Nginx配置文件是否OK

sudo /usr/local/openresty/nginx/sbin/nginx -tnginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful

没问题直接重启openresty做事即可。

sudo systemctl restart openresty.service安全组设置

打开安全组设置,在[入方向] 开放1935端口,1935端口是rtmp默认监听端口,必须在这里设置开放,否则在做事器中打开和监听1935端口后公网环境连接不到该端口。

OBS 推流

推流地址:rtmp://{做事器公网IP}/live/tinywan2024

VLC 拉流播放

拉流地址:rtmp://{做事器公网IP}/live/tinywan2024

涌现“is not binary compatible in”缺点的办理方案

sudo /usr/local/openresty/nginx/sbin/nginx -tnginx: [emerg] module "/usr/local/openresty/nginx/modules/ngx_rtmp_module.so" is not binary compatible in /usr/local/openresty/nginx/conf/nginx.conf:7nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test failed

缘故原由

第三方模块的编译中包含的署名和利用的nignx不一致。

办理方案

先通过 nginx -V 命令得到当前配置的configure配置

/usr/local/openresty/nginx/sbin/nginx -Vnginx version: openresty/1.19.3.1built by gcc 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04) built with OpenSSL 1.1.1 11 Sep 2018TLS SNI support enabledconfigure arguments: --prefix=/usr/local/openresty/nginx \--with-cc-opt='-O2 -O3' --add-module=../ngx_devel_kit-0.3.1 \--add-module=../iconv-nginx-module-0.14 \--add-module=../echo-nginx-module-0.62 \--add-module=../xss-nginx-module-0.06 \--add-module=../ngx_coolkit-0.2 \--add-module=../set-misc-nginx-module-0.32 \--add-module=../form-input-nginx-module-0.12 \--add-module=../encrypted-session-nginx-module-0.08 \--add-module=../srcache-nginx-module-0.32 \--add-module=../ngx_lua-0.10.19 \--add-module=../ngx_lua_upstream-0.07 \--add-module=../headers-more-nginx-module-0.33 \--add-module=../array-var-nginx-module-0.05 \--add-module=../memc-nginx-module-0.19 \--add-module=../redis-nginx-module-0.3.7 \--add-module=../rds-json-nginx-module-0.15 \--add-module=../rds-csv-nginx-module-0.09 \--add-module=../ngx_stream_lua-0.0.9 \--with-ld-opt=-Wl,-rpath,/usr/local/openresty/luajit/lib \--with-pcre-jit --with-stream --with-stream_ssl_module \--with-stream=dynamic --with-file-aio --with-threads \--with-http_v2_module --with-http_realip_module \--with-http_mp4_module --with-http_gzip_static_module \--with-http_ssl_module --with-http_stub_status_module \--with-http_xslt_module --with-openssl-opt='-g enable-tlsext' \--with-stream --with-stream_ssl_preread_module

在复制所有的配置命令。
添加到:

./configure [“你的nignx -V 得到的配置参数”] --add-dynamic-module=/home/www/build/nginx-rtmp-module

把稳事变:

动态模块只能在 Nginx 1.9.11 及以上版本中利用。
加载和卸载模块须要 root 权限。
加载和卸载模块会影响 Nginx 的性能,建议在低峰期进行操作。
标签:

相关文章

大数据时代,高清视界下的无限可能

随着科技的飞速发展,大数据已经渗透到了我们生活的方方面面。在这个信息爆炸的时代,如何从海量数据中挖掘有价值的信息,成为了各个领域关...

网站推广 2024-12-16 阅读0 评论0