37.FFmpeg+OpenCV直播推流(nginx服务器搭建和测试)

简介:
介绍

Nginx是一款轻量级的Web服务器反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。其特点是占有内存少,并发能力强。今天来分享一下如何安装配置nginx服务器,并应用于直播推流中。

开发环境

Ubuntu 16 64位+Windows10

安装

1.root用户登录Ubuntu,使用如下命令下载nginx

wget http://nginx.org/download/nginx-1.12.1.tar.gz

2.nginx依赖于一些开源库,这些我们需要下载下来

apt install  libssl-dev
注意zlib1g   g前边是个数字1不是字母l
apt install zlib1g-dev
apt install libpcre3-dev
apt install gcc
apt install g++

3.接下来将nginx解压

tar -xvf nginx-1.12.1.tar.gz 

4.下载rtmp模块
使用git下载,没有下载git先安装

apt install git

在github上找到nginx-rtmp-module

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

将这个module添加到nginx上

./configure --add-module=/root/nginx-1.12.1/nginx-rtmp-module

nginx关联module.png
5.开始编译

make 

可能在系统中已经安装了nginx,为了防止无法覆盖,先rm

这是个默认安装目录
rm -r /usr/local/nginx/

6.安装

make install

然后进入到usr/local/nginx目录
注意这是root根目录下的

cd usr/local/nginx/sbin/

7.执行nginx

./nginx

8.查看是否已运行

ps -ef|grep nginx

在浏览器上输入ip查看如果显示welcome to nginx表示已经运行成功
nginx启动成功.png
9.rtmp配置
进入nginx安装目录:usr/local/nginx/conf修改nginx.conf文件(注意是安装目录,不要傻傻的去解压包中修改)

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                }
        }
}

添加了这个之后,就可以推流了,我们使用ffmepg推一把试试.注意live是什么,端口是什么

ffmpeg -i C:\Users\renzhenming\Desktop\一首《秋意浓》打动阿琴冷酷的心,星爷太会泡妞了.mp4 -f flv -c copy rtmp://192.168.1.108/live

然后通过vcl播放器,输入rtmp://192.168.1.108/live可以看到播放成功

然后在设置一把通过浏览器监听nginx状态,还是在nginx.conf中添加

server {
        listen 8080;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
                //样式表的位置,这个表是nginx-rtmp-module中的
                root /root/nginx-1.12.1/nginx-rtmp-module;
        }
    }

这样一来,我们通过浏览器就可以看到推流的状态了
在浏览器中输入

http://192.168.xx.xx:8080/stat

完整的nginx.conf文件如下,注意看我们添加的配置放置的位置

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

rtmp {
        server {
                listen 1935;
                chunk_size 4096;
                application live {
                        live on;
                }
        }
}

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;
        location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
                root /root/nginx-1.12.1/nginx-rtmp-module;
        }
    }
    server {
        listen       80;
        server_name  localhost;

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

}

至此,nginx配置完毕

相关文章
|
2月前
|
网络协议 安全 测试技术
手撕测试tcp服务器效率工具——以epoll和io_uring对比为例
手撕测试tcp服务器效率工具——以epoll和io_uring对比为例
40 2
|
2天前
|
应用服务中间件 Linux 开发工具
如何在阿里云服务器快速搭建部署Nginx环境
以下是内容的摘要: 本文档主要介绍了在阿里云上购买和配置服务器的步骤,包括注册阿里云账号、实名认证、选择和购买云服务器、配置安全组、使用Xshell和Xftp进行远程连接和文件传输,以及安装和配置Nginx服务器的过程。在完成这些步骤后,你将能够在服务器上部署和运行自己的网站或应用。
|
1月前
|
弹性计算 分布式计算 DataWorks
DataWorks报错问题之ecs自建数据库连通性测试报错如何解决
DataWorks是阿里云提供的一站式大数据开发与管理平台,支持数据集成、数据开发、数据治理等功能;在本汇总中,我们梳理了DataWorks产品在使用过程中经常遇到的问题及解答,以助用户在数据处理和分析工作中提高效率,降低难度。
|
1月前
|
弹性计算 算法 应用服务中间件
倚天使用|Nginx性能高27%,性价比1.5倍,基于阿里云倚天ECS的Web server实践
倚天710构建的ECS产品,基于云原生独立物理核、大cache,结合CIPU新架构,倚天ECS在Nginx场景下,具备强大的性能优势。相对典型x86,Http长连接场景性能收益27%,开启gzip压缩时性能收益达到74%。 同时阿里云G8y实例售价比G7实例低23%,是Web Server最佳选择。
|
1月前
|
弹性计算 缓存 测试技术
阿里云2核4g服务器(费用价格/性能测试/支持人数)
阿里云2核4g服务器能支持多少人访问?2核4G服务器并发数性能测试,阿小云账号下的2核4G服务器支持20人同时在线访问,然而应用不同、类型不同、程序效率不同实际并发数也不同,2核4G服务器的在线访问人数取决于多个变量因素
|
1月前
|
弹性计算 缓存 测试技术
2核4g服务器能支持多少人访问?阿里云2核4G服务器并发数测试
2核4g服务器能支持多少人访问?阿里云2核4G服务器并发数测试,2核4G服务器并发数性能测试,阿小云账号下的2核4G服务器支持20人同时在线访问,然而应用不同、类型不同、程序效率不同实际并发数也不同,2核4G服务器的在线访问人数取决于多个变量因素
|
2月前
|
网络协议 Unix 应用服务中间件
如何进行 Nginx HTTPS服务器搭建
【2月更文挑战第6天】
63 0
|
2月前
|
负载均衡 JavaScript 应用服务中间件
强大的WEB服务器-Nginx
强大的WEB服务器-Nginx
29 0
|
2月前
|
存储 负载均衡 监控
epoll服务器百万并发测试
epoll服务器百万并发测试
31 1
|
2月前
|
弹性计算 数据中心
阿里云香港服务器详细介绍_BGP多线精品测试_CN2高速网络
阿里云香港服务器中国香港数据中心网络线路类型BGP多线精品,中国电信CN2高速网络高质量、大规格BGP带宽,运营商精品公网直连中国内地,时延更低,优化海外回中国内地流量的公网线路,可以提高国际业务访问质量。阿里云百科来详细介绍阿里云香港云服务器

热门文章

最新文章