使用nginx 共享服务器中的视频

Posted loveskey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了使用nginx 共享服务器中的视频相关的知识,希望对你有一定的参考价值。

nginx 共享服务器中的视频

如果服务器处于内网或者没有公网ip,可以使用 相关软件进行打洞或转发 如: frpc https://github.com/fatedier/frpholer https://github.com/wisdom-projects/holer

服务器中有很多视频,有时候在外面想要看些视频的时候就有些麻烦了.可以通过http共享然后使用vlc之类播放器播放.但是需要自制播放列表很是麻烦.

使用nginx_rtmp_module 查件可以实现 直接从目录方式访问点击视频就可以播放的效果.

所以nginx是必要的.而且要源码编译,编译时候要加上nginx_rtmp_module 这个模块.

下载编译安装

必要的编译包自行安装.gcc之类还有一些依赖包

 wget http://nginx.org/download/nginx-1.16.0.tar.gz
 wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
 tar xf nginx-1.16.0.tar.gz
 unzip master.zip
 cd nginx-1.16.0
 mv * ../
 cd ..
 ./configure --with-http_ssl_module  --add-module=../nginx-rtmp-module-master
 make -j4
 make install

至此nginx编译安装完成.

配置nginx

vim /usr/local/nginx/conf/nginx.conf

#user  nobody;
worker_processes  2;

#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;


rtmp 
    server 
        listen 1935;
 
        application vod 
            play /mnt/s2t; #这是一个目录的名称,如果是linux,则写具体位置如/opt/video
        
    



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;

    server 
        listen       8080;
        server_name  localhost;

        charset utf8;

        #access_log  logs/host.access.log  main;

        location / 
            root   /mnt/s2t;
        autoindex on;
        auth_basic "needAuth";
        auth_basic_user_file /usr/local/nginx/conf/passwd.db;
        index  index.html index.htm;
        


        location /test.flv 
            root video;
        
 
 
        location /stat 
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        
 
        location /stat.xsl 
            root html;
        
 

生成登录验证密码文件

htpasswd -c /usr/local/nginx/conf/passwd.db makeit

测试访问

/usr/local/nginx/sbin/nginx -s reload
技术图片

右键支持倍速播放哦.

参考:

关于模块更多信息

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

以上是关于使用nginx 共享服务器中的视频的主要内容,如果未能解决你的问题,请参考以下文章

C 中的共享内存代码片段

使用 Nginx 或 Node 流式传输保存的 HLS 视频

片段转换:共享元素

nginx负载均衡集群中的session共享说明

如何使用两个片段实现视频和视频列表

FragmentNavigator 共享过渡不起作用