用nginx实现一个直播服务—RTMP推流和HTTP-FLV拉流

本文详细介绍了如何在CentOS7上配置和安装Nginx,包括编译安装过程、配置Nginx以支持RTMP和HTTP-FLV直播,以及启动和测试推流和拉流服务。此外,还涵盖了摄像头数据采集和查看服务器统计信息的步骤。

目录

一、环境准备

二、安装编译nginx所需的安装包和下载nginx原代码包

三、nginx配置

四、启动nginx服务

五、测试推流和拉流服务

六、摄像头数据采集

七、查看统计


这篇文章主要记录用nginx实现直播服务,通过RTMP推流和通过HTTP-FLV或RTMP拉流,并在页面中播放。

一、环境准备

CentOS Linux release 7.3.1611 (Core)  3.10.0-514.el7.x86_64

nginx1.25

二、安装编译nginx所需的安装包和下载nginx原代码包

#安装编译nginx环境包

yum install gcc -y
yum install pcre pcre-devel -y
yum install openssl openssl-devel -y
yum install wget -y

#下载nginx和nginx-http-flv-module原代码

mkdir -p /opt/backup/docker-build/nginx-flv/nginx-src
cd /opt/backup/docker-build/nginx-flv/nginx-src
wget http://nginx.org/download/nginx-1.25.0.tar.gz

tar -zxf nginx-1.25.0.tar.gz
git clone https://github.com/winshining/nginx-http-flv-module.git

#编译安装,完成后会安装在/usr/local/nginx-flv下

./configure --prefix=/user/local/nginx-flv --with-http_ssl_module --with-http_secure_link_module --add-module=nginx-http-flv-module-master
make 
make install

三、nginx配置

#nginx主配置文件   vim /usr/local/nginx-flv/conf/nginx.conf

#user  nobody;
worker_processes  auto;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

error_log  logs/error.log warn;
pid        logs/nginx.pid;


events {
    worker_connections  10240;
    use epoll;
    multi_accept on;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    server_names_hash_bucket_size 128;
    client_header_buffer_size 32k;
    large_client_header_buffers 4 32k;
    client_max_body_size 50m;

    log_format nginx_json '{    "time": "$time_local", '
                               '"remote_ip": "$remote_addr", '
                               '"remote_user": "$remote_user", '
                               '"domain":"$host", '
                               '"responsetime":$request_time, '
                               '"request": "$request", '
                               '"response": "$status", '
                               '"bytes": $body_bytes_sent, '
                               '"referrer": "$http_referer", '
                               '"upstreamtime":"$upstream_response_time", '
                               '"upstreamaddr":"$upstream_addr", '
                               '"x_forwarded_for":"$http_x_forwarded_for", '
                               '"agent": "$http_user_agent" }';

    access_log  logs/access.log  nginx_json;

    sendfile        on;
    tcp_nopush     on;
    server_tokens off;
    keep
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

归海听雪

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值