zoukankan      html  css  js  c++  java
  • nginx搭建点播视频(Mp4播放)

    首先,环境中必然要有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  协议

  • 相关阅读:
    跳出iframe
    leetcode 225. Implement Stack using Queues
    leetcode 206. Reverse Linked List
    leetcode 205. Isomorphic Strings
    leetcode 203. Remove Linked List Elements
    leetcode 198. House Robber
    leetcode 190. Reverse Bits
    leetcode leetcode 783. Minimum Distance Between BST Nodes
    leetcode 202. Happy Number
    leetcode 389. Find the Difference
  • 原文地址:https://www.cnblogs.com/Tang-Yuan/p/9856268.html
Copyright © 2011-2022 走看看