• Nginx流媒体服务器搭建


    一、安装nginx服务依赖
    root@nginx:~# apt-get update
    root@nginx:~# apt install build-essential #安装gcc
    root@nginx:~# apt install libpcre3 libpcre3-dev # nginx需要
    root@nginx:~# apt install libssl-dev
    root@nginx:~# apt-get install zlib1g-dev

    二、下载相关软件包
    root@nginx:~# wget http://h264.code-shop.com/download/nginx_mod_h264_streaming-2.2.7.tar.gz
    root@nginx:~# wget http://nginx.org/download/nginx-1.15.9.tar.gz
    root@nginx:~# git clone https://github.com/arut/nginx-rtmp-module
    root@nginx:~# git clone https://github.com/pschultz/ngx_http_allow_methods_module.git

    三、解压相关软件包
    root@nginx:~# tar xf nginx-1.15.9.tar.gz
    root@nginx:~# tar xf nginx_mod_h264_streaming-2.2.7.tar.gz

    四、编译安装nginx(ngx_http_allow_methods_module模块用于允许http访问的请求类型,不需要安装)
    root@nginx:~/nginx-1.15.9# ./configure --prefix=/usr/local/nginx --add-module=/root/nginx_mod_h264_streaming-2.2.7 \
    --add-module=/root/nginx-rtmp-module --with-http_flv_module --with-http_mp4_module \
    --with-http_gzip_static_module --with-http_stub_status_module --add-module=/root/ngx_http_allow_methods_module

    五、编译安装nginx_mod_h264_streaming-2.2.7模块报错编辑ngx_http_streaming_module.c文件,把158到161行注释掉
    root@nginx:~# vim nginx_mod_h264_streaming-2.2.7/src/ngx_http_streaming_module.c

    157   /* TODO: Win32 */
    158 //  if (r->zero_in_uri)
    159 //  {
    160 //    return NGX_DECLINED;
    161 //  }

    六、编辑Makefile文件,删除-Werror
    root@nginx:~/nginx-1.15.9# vim objs/Makefile

     
     root@nginx:~/nginx-1.15.9# make && make install

    七、nginx配置

    #user  nobody;
    worker_processes  1;
    
    #error_log  logs/error.log;
    #error_log  logs/error.log  notice;
    #error_log  logs/error.log  info;
    
    #pid        logs/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    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;
        gzip_min_length 1k;
        gzip_buffers 4 16k;
        gzip_comp_level 2;
        gzip_types text/plain application/x-javascript text/css application/xml;
        gzip_vary on;
    
        output_buffers 1 32k;
        postpone_output 1460;
        client_header_timeout 3m;
        client_body_timeout 3m;
        send_timeout 3m;
        tcp_nopush on;
        tcp_nodelay on;
    
        open_file_cache max=64 inactive=30d;
        open_file_cache_min_uses 1;
        open_file_cache_valid 3m;
    
        server {
            listen       80;
            server_name  i.video.com;
    
            charset utf-8;
    
            location ~ \.mp4$|\.m4v$ {
                root   html/mp4m4v/;
            }
    
            location ~ \.flv$ {
                root   html/flv/;
            }
    } server { listen
    80; server_name www.video.com; #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; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # #location ~ \.php$ { # proxy_pass http://127.0.0.1; #} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # another virtual host using mix of IP-, name-, and port-based configuration # #server { # listen 8000; # listen somename:8080; # server_name somename alias another.alias; # location / { # root html; # index index.html index.htm; # } #} # HTTPS server # #server { # listen 443 ssl; # server_name localhost; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m; # ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} }

    八、index.html页面

    <html>
      <head>
        <link href="https://vjs.zencdn.net/7.17.0/video-js.css" rel="stylesheet" />
      
        <!-- If you'd like to support IE8 (for Video.js versions prior to v7) -->
        <!-- <script src="https://vjs.zencdn.net/ie8/1.1.2/videojs-ie8.min.js"></script> -->
      </head>
      
      <body>
        <video
          id="my-video"
          class="video-js"
          controls
          preload="auto"
          width="640"
          height="264"
          poster="MY_VIDEO_POSTER.jpg"
          data-setup="{}"
        >
          <source src="http://i.video.com/abc.mp4" type="video/mp4" />
          <p class="vjs-no-js">
            To view this video please enable JavaScript, and consider upgrading to a
            web browser that
            <a href="https://videojs.com/html5-video-support/" target="_blank"
              >supports HTML5 video</a
            >
          </p>
        </video>
      
        <script src="https://vjs.zencdn.net/7.17.0/video.min.js"></script>
      </body>
    </html>

    九、访问http://www.video.com

    十、CentOS8安装ffmpeg
    [root@centos8 ~]# dnf install https://download1.rpmfusion.org/free/el/rpmfusion-free-release-8.noarch.rpm
    [root@centos8 ~]# wget http://rpmfind.net/linux/centos/8.5.2111/PowerTools/x86_64/os/Packages/SDL2-2.0.10-2.el8.x86_64.rpm
    [root@centos8 ~]# rpm -ivh SDL2-2.0.10-2.el8.x86_64.rpm
    [root@centos8 ~]# dnf install ffmpeg

    参考链接:
    https://leefige.github.io/2019/03/05/%E5%9F%BA%E4%BA%8ENginx%E9%85%8D%E7%BD%AEWeb%E8%A7%86%E9%A2%91%E6%B5%81%E5%AA%92%E4%BD%93%E6%9C%8D%E5%8A%A1%E5%99%A8/
        https://lxneng.com/posts/160?lang=zh_CN        #编译nginx报错解决
        https://github.com/pschultz/ngx_http_allow_methods_module
        http://rpmfind.net/linux/rpm2html/search.php?query=libSDL2-2.0.so.0()(64bit)
        http://t.zoukankan.com/architectforest-p-12807683.html

  • 相关阅读:
    kafka 消息推送报错"dial tcp: lookup iZ2ze2k3******7abjcsyZ on 219.141.140.10:53: no such host"
    MacBook安装Homebrew的国内安装脚本 告别龟速下载安装
    docker info命令的使用和返回结果描述
    Python requests.post方法中data与json参数区别
    redis master-slave python switch logic (升级版,序列七)
    ELKF日志收集系统
    MySQL 中的concat函数使用
    程序员的街舞“梦”
    第一份工作没有工资,信不信
    Java中的享元设计模式,涨姿势了!
  • 原文地址:https://www.cnblogs.com/xwupiaomiao/p/15660602.html
Copyright © 2020-2023  润新知