nginx搭建流媒体服务器

nginx搭建流媒体服务器

拉取代码仓库

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

编译安装

cd nginx
auto/configure --with-http_ssl_module --with-http_mp4_module --with-http_flv_module --add-module=../nginx-rtmp-module
make
sudo make install

编写配置文件

#media.conf
#user  nobody;
worker_processes  4;

#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 {
    server {
        listen 80;
        location / {
            root    html;
            index   index.html;
        }

        location ~ \.mp4$ {
            root    media;
            mp4;
        }

        location ~ \.flv$ {
            root    media;
            flv;
        }
    }
}

rtmp {
    server {
        listen 1935;
        application live {
            play    media;
        }
    }
}

启动nginx服务

sudo /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/media.conf

测试

在配置文件中$root目录下放置.mp4/.flv文件,示例中路径即/usr/local/nginx/media

使用VLC、ffplay或者本人的hplayer即可测试播放,如

ffplay http://ip:80/test.mp4
ffplay rtmp://ip:1953/live/test.mp4
ithewei CSDN认证博客专家 c/c++ Qt libhv
编程之路,其路漫漫,吾将上下而求索
https://github.com/ithewei
https://hewei.blog.csdn.net
©️2020 CSDN 皮肤主题: 代码科技 设计师:Amelia_0503 返回首页