nginx搭建点播视频(Mp4播放)

news/2024/7/9 19:27:28 标签: 运维, epoll, 操作系统

首先,环境中必然要有gcc-c++环境

  yum -y install gcc-c++

1 使用openresty

这里使用的是1.11.2.1版本的openresty和1.0.2版本的openssl

      root@King: ~#yum install readline-devel pcre-devel openssl-devel gcc

      root@King: ~# tar -zxvf openresty-1.11.2.1.tar.gz

      root@King: ~#tar -zxvf openssl-1.0.2h.tar.gz

      root@King: ~#cd openresty-1.11.2.1

      root@King: ~#./configure --prefix=/app/openresty --user=xxx --group=xxx --with-http_v2_module --with-openssl=/home/appdeploy/nginx/openssl-1.0.2h --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

 

可以在这里设置user和group,也可以稍后使用下面的命令进行设置

chown -R [user]:[group] 文件夹名上面的命令执行之后,编译并安装openrestry,安装目录就是配置中指定的/app/openrestry

   root@King: ~#make && make install

 

如果安装的时候没有权限,可以用su切到root,注意安装之后的openrestry目录的权限即可。
此时openrestry已经安装好,到安装目录中修改openrestry下的nginx文件夹下的nginx.conf配置文件

worker_processes 1;       #工作进程数,一般设置为1就可以了
#error_log  /usr/local/nginx/logs/error.log  crit;
#pid        /usr/local/nginx/logs/nginx.pid;
events {
        use epoll;
        worker_connections      65535;
        }
http {
        include       mime.types;
        default_type  application/octet-stream;
        log_format main  '$remote_addr - $remote_user [$time_local] '
                                                '"$request" $status $bytes_sent '
                                                '"$http_referer" "$http_user_agent" '
                                                '"$gzip_ratio"';
        keepalive_timeout  60;
        server_names_hash_bucket_size  128;
        client_header_buffer_size    32k;
        large_client_header_buffers  4 32k;
        access_log off;
        gzip on;
        gzip_min_length  1100;
        gzip_buffers     4 8k;
        gzip_types       text/plain;
        output_buffers   1 32k;
        postpone_output  1460;
        client_header_timeout  3m;
        client_body_timeout    3m;
        send_timeout           3m;
        sendfile                on;
        tcp_nopush              on;
        tcp_nodelay             on;
    server {
           listen 8080;
           server_name  10.202.94.16;
           root    /app/openresty/nginx/html/;
           limit_rate_after 30m;   
           limit_rate 700k;            #这里根据需要设置,意思是视频缓冲30M之后,限速为700k/s
           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;
           }
    }
}

 

修改之后,启动nginx服务器

  root@King: ~#/app/openresty/nginx/sbin/nginx -c /app/openresty/nginx/conf/nginx.conf

将mp4文件放到/app/openresty/nginx/html/目录下
在浏览器上访问http://10.202.94.16:8080/xxx.mp4即可。

2 使用nginx

建议采用nginx 1.1.3版本之后的nginx,默认支持mp4,就无需再安装一堆繁琐的插件。这里使用的是1.3.14版本。

  root@King: ~# tar -zxvf nginx-1.3.14.tar.gz

  root@King: ~# cd nginx-1.3.14

  root@King: ~# ./configure --prefix=/app/nginx --user=xxx --group=xxx --with-select_module --with-poll_module --with-file-aio --with-http_ssl_module --with-http_realip_module --with-http_gzip_static_module --with-http_secure_link_module --with-http_sub_module --with-http_stub_status_module --with-http_perl_module --with-http_mp4_module --with-http_flv_module

  root@King: ~# make&& make install

 

然后同样的,去/app/nginx做和openrestry中的nginx一样的修改即可,注意修改目录。

效果如下所示,此时的视频是横跨整个屏幕的,如果想要修改,比如做页面的内嵌视频,可以把视频放到HTML5页面中,再通过nginx服务器访问html文件即可。有个开源的video.js很好用,这里就不再赘述了。

 

报错信息处理:


从 http://nginx.org/download/nginx-1.9.15.tar.gz 下载nginx包(或者wget http://nginx.org/download/nginx-1.9.15.tar.gz直接在Linux上用命令下载)

解压并转到目录下

  root@King: ~# tar -zxvf nginx-1.9.15.tar.gz
  root@King: ~# cd nginx-1.9.15


设置一下配置信息

  root@King: ~#./configure --prefix=/usr/local/nginx ,或者不执行此步,直接默认配置


编译安装

    root@King: ~# make
    root@King: ~# make install


make的过程是把各种语言写的源码文件,变成可执行文件和各种库文件;
make install是把这些编译出来的可执行文件和库文件复制到合适的地方。

可能出现错误在配置信息

    root@King: ~#./configure --prefix=/usr/local/nginx 的时,出现错误:
/configure: error: the HTTP rewrite module requires the PCRE library.

解决方法:安装pcre
 

 root@King: ~# yum -y install pcre pcre-devel


-y 是跳过所有需要手动确认的环节

缺少ssl错误,错误信息如下:
root@King: ~# ./configure
error: the HTTP cache module requires md5 functions
from OpenSSL library. You can either disable the module by using --without-http-cache option, or install the OpenSSL library into the system,or build the OpenSSL library statically from the source with nginx by using --with-http_ssl_module --with-openssl=<path> options.


解决方法:安装openssl

  root@King: ~# yum -y install openssl openssl-devel


缺少编译器,错误信息如下:

    root@King: ~# ./configure
    error: C compiler cc is not found


解决方法:安装gcc-c++

    root@King: ~# yum -y install gcc-c++ autoconf automake


autoconf是自动配置,automake是自动编译
缺少zlib包,错误信息如下:

    root@King: ~# ./configure: 
    error: the HTTP gzip module requires the zlib library.You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option.


解决方法:安装zlib

    root@King: ~# yum install -y zlib-devel


确实libxml2,错误信息如下:

    root@King: ~# ./configure: 
    error: the HTTP XSLT module requires the libxml2/libxslt libraries. You can either do not enable the module or install the libraries.


解决方法:

    root@King: ~# yum -y install libxml2 libxml2-dev
    root@King: ~# yum -y install libxslt-devel


http_image_filter_module是nginx提供的集成图片处理模块,需要gd-devel的支持,错误信息如下:

    root@King: ~# ./configure: 
    error: the HTTP image filter module requires the GD library.You can either do not enable the module or install the libraries.


解决方法:

    root@King: ~# yum -y install gd-devel


缺少ExtUtils,错误信息如下:

    root@King: ~# ./configure: 
    error: perl module ExtUtils::Embed is required


解决方法:

    root@King: ~# yum -y install perl-devel perl-ExtUtils-Embed


缺少GeoIP,错误信息如下:

    root@King: ~# ./configure:
     error: the GeoIP module requires the GeoIP library.You can either do not enable the module or install the library.


解决方法:

    root@King: ~# yum -y install GeoIP GeoIP-devel GeoIP-data


安装完成后启动安装成功后 /usr/local/nginx 目录下如下
fastcgi.conf koi-win nginx.conf.default
fastcgi.conf.default logs scgi_params
fastcgi_params mime.types scgi_params.default
fastcgi_params.default mime.types.default uwsgi_params
html nginx uwsgi_params.default
koi-utf nginx.conf win-utf
启动
确保系统的 80 端口没被其他程序占用,运行/usr/local/nginx/nginx 命令来启动 Nginx,

    root@King: ~# netstat -ano|grep 80


如果查不到结果后执行,有结果则忽略此步骤(ubuntu下必须用sudo启动,不然只能在前台运行)

    root@King: ~# sudo /usr/local/nginx/nginx


打开浏览器访问此机器的 IP,如果浏览器出现 Welcome to nginx! 则表示 Nginx 已经安装并运行成功。

 

 

直播视频搭建:

rtmp  协议

转载于:https://www.cnblogs.com/Tang-Yuan/p/9856268.html


http://www.niftyadmin.cn/n/629926.html

相关文章

烹饪发烧友服务器无响应怎么解决,烹饪发烧友-风靡全球的模拟烹饪游戏无法连接服务器是什么原因...

烹饪发烧友-风靡全球的模拟烹饪游戏中不少玩家反馈都会遇到烹饪发烧友-风靡全球的模拟烹饪游戏无法连接服务器是什么原因的问题&#xff0c;那么怎么解决这个问题呢&#xff0c;这边ourplay小编为大家分享几个解决方案。烹饪发烧友-风靡全球的模拟烹饪游戏游戏简介烹调是一份艰…

python实现排列组合公式算法_最小树——Dijkstra算法及Python实现

最小树问题是一类非常简单的网络最优化问题&#xff0c;它在许多网络设计问题中有着广泛的应用。常用的求最小树的算法有&#xff1a;破圈法、避圈法、边割法和Dijkstra算法等等。其中&#xff0c;破圈法、避圈法和边割法简单明了&#xff0c;便于在图上操作&#xff0c;但是破…

LAMP架构中部署Zabbix监控服务

Zabbix监控服务 zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。zabbix能监视各种网络参数&#xff0c;保证服务器系统的安全运营&#xff1b;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。zabbix由2部分构成&#…

console linux 口 没输出_Console很飒,不止log

日常工作中&#xff0c;难免存在为了代码调试而试验性地输出一些东西&#xff0c;曾经都爱用alert()&#xff0c;高兴了弹个数据&#xff0c;但让人头疼的是&#xff0c;它会中断代码执行&#xff0c;得手动关掉&#xff0c;所以有人就用 document.write()&#xff0c;这样也有…

bootstrapValidator关于js,jquery动态赋值不触发验证(不能捕获“程序赋值事件”)解决办法...

关键点一&#xff1a;修改excluded和trigger的配置 $("#department-add-modal-form").bootstrapValidator({//excluded:[":hidden",":disabled",":not(visible)"] ,//bootstrapValidator的默认配置excluded:[":disabled"],/…

如何让小程序页面更顺滑_小程序二十七 页面模板

崇张氏从小区向外拍的望京soho望京soho&#xff0c;广州大剧院&#xff0c;南京青奥中心&#xff0c;大兴机场&#xff0c;都是建筑设计大师扎哈的作品。人文感受&#xff1a;相关信息系统&#xff0c;其实对产品化要求相当高&#xff0c;企业内部相关业务部门抽调专业业务人员…

浏览器与css的兼容,CSS浏览器兼容性与解决

一、超链接访问后hover样式不出现1、现象描述&#xff1a;同时设置了a:visited和a:hover样式&#xff0c;但一旦超链接点击过后&#xff0c;hover的样式就不再出现了。2、解决方法&#xff1a;调整样式顺序为先a:visited再a:hover即可。a标签四种状态的排序&#xff1a;l(link)…

中project报错_SparkSQL中map字段不能进行union、intersect、except操作吗?

通过SparkSQL&#xff0c;对两个存在map类型字段的Hive表进行union操作&#xff0c;报如下错误&#xff1a;org.apache.spark.sql.AnalysisException: Cannot have map type columns in DataFrame which calls set operations(intersect, except, etc.), but the type of colum…