温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

nginx如何搭建基于http协议的视频点播服务器

发布时间:2021-11-05 16:28:34 来源:亿速云 阅读:412 作者:柒染 栏目:建站服务器

本篇文章给大家分享的是有关nginx如何搭建基于http协议的视频点播服务器,小编觉得挺实用的,因此分享给大家学习,希望大家阅读完这篇文章后可以有所收获,话不多说,跟着小编一起来看看吧。

nginx搭建基于http协议的视频点播服务器

1,下载安装nginx 稳定版,http://nginx.org/en/download.html

2,安装相关库pcre zlib  openssl,先看有没有安装。

ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
http://zlib.net/zlib-1.2.8.tar.gz
http://www.openssl.org/source/openssl-1.0.1f.tar.gz

     [root@localhost vsftpd]# rpm -qa pcre
     pcre-7.8-7.el6.i686


3,下载nginx_mod_h364_streaming-2.2.7.tar.gz
http://h364.code-shop.com/download/nginx_mod_h364_streaming-2.2.7.tar.gz

     解压nginx_mod_h364_streaming-2.2.7.tar.gz,添加flv,mp4模块。解压到和nginx源码同级的目录。

4,下载nginx-rtmp-module
https://github.com/arut/nginx-rtmp-module
unzip nginx-rtmp-module-master

5, 因为flv 和http是nginx自带的所以不用下载这个模块。

./configure \
--sbin-path=/usr/local/sbin \
--add-module=../nginx-rtmp-module-1.0.2 \
--with-http_ssl_module \
--add-module=../nginx_mod_h364_streaming-2.2.7 \
--with-pcre=../pcre-8.32 \
--with-zlib=../zlib-1.2.8  \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_mp4_module  

./configure --add-module=/usr/server/nginx_mod_h364_streaming-2.2.7 --sbin-path=/usr/local/sbin --with-debug

选择需要的编译选项
Nginx的编译选项还是不少 的,基本上都是定制位置和模块,分别是:
1)--sbin-path=/usr/local/sbin
从源码编译Nginx会安装在/usr/local/nginx目录下(你可以使用参数--prefix=<path>指定自己需要的位置),然后会将bin文件放在/usr/local/nginx/sbin/nginx,虽然比较清晰,但是和我们一般的习惯不同

(作为程序员的我们更习惯在/usr/local /sbin下寻找bin文件);

2)--with-http_ssl_module
主要是提供https访问支持的





make

make install

5,make

      可能遇到问题1
      /root/nginx_mod_h364_streaming-2.2.7/src/ngx_http_streaming_module.c: In function ‘ngx_streaming_handler’:
     /root/nginx_mod_h364_streaming-2.2.7/src/ngx_http_streaming_module.c:158: error: ‘ngx_http_request_t’ has no member named ‘zero_in_uri’
     make[1]: *** [objs/addon/src/ngx_http_h364_streaming_module.o] Error 1
     make[1]: Leaving directory `/root/nnginx-1.5.9'
     make: *** [build] Error 2
     那么将src/ngx_http_streaming_module.c文件中以下代码删除或者是注释掉就可以了


/* TODO: Win32 */
if (r->zero_in_uri)
{
     return NGX_DECLINED;
}

可能遇到问题2
../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c: 在函数‘esds_read’中:

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c:377:16: 错误: 变量‘stream_priority’被设定但未被使用 [-Werror=unused-but-set-variable]

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c:376:12: 错误: 变量‘stream_id’被设定但未被使用 [-Werror=unused-but-set-variable]

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c: 在函数‘stsd_parse_vide’中:

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c:529:22: 错误: 变量‘level_indication’被设定但未被使用 [-Werror=unused-but-set-variable]

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c:528:22: 错误: 变量‘profile_compatibility’被设定但未被使用 [-Werror=unused-but-set-variable]

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c:527:22: 错误: 变量‘profile_indication’被设定但未被使用 [-Werror=unused-but-set-variable]

../nginx_mod_h364_streaming-2.2.7/src/mp4_reader.c:526:22: 错误: 变量‘configuration_version’被设定但未被使用 [-Werror=unused-but-set-variable]

cc1: all warnings being treated as errors

make[1]: *** [objs/addon/src/mp4_reader.o] 错误 1

解决方法:
# vim objs/Makefile (修改objs/Makefile文件, 去掉其中的"-Werror"), 然后就能够正常编译了.

6, make install

7,配置 nginx.conf  主要是server部分


server {
            listen       8999;
            server_name  192.168.1.104;
            root    /usr/local/nginx/html/flv_file/;
            limit_rate_after 5m;   
            limit_rate 512k;        
   
            index   index.html;
            charset utf-8;
    
            location ~ \.flv {
                flv;
            }
    
            location ~ \.mp4$ {
                mp4;
            }
    
    
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    }

8,启动nginx,创建/usr/local/nginx/html/flv_file/目录。


 cd /usr/local/nginx
启动  ./nginx
优雅关闭   ./nginx -s quit
快速关闭   ./nginx -s stop


nginx -s reload  :修改配置后重新加载生效
nginx -s reopen  :重新打开日志文件
nginx -t -c /path/to/nginx.conf 测试nginx配置文件是否正确

/usr/local/sbin/nginx  -c /usr/local/nginx/conf/nginx.conf -s reload


9,上传mp4视频文件CY.mp4

10,写个html测试。看之前的文章用jwplayer来测试,但是我这边一直报jwplayer udefined。


Loading the player ...


<video src="http://192.168.1.104:8999/CY.mp4" controls="controls" width="50%" height="50%">

以上就是nginx如何搭建基于http协议的视频点播服务器,小编相信有部分知识点可能是我们日常工作会见到或用到的。希望你能通过这篇文章学到更多知识。更多详情敬请关注亿速云行业资讯频道。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI