微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐