ubuntu 安装 nginx配置RTMP协议的配置文件

安装教程:

nginx服务器配置支持RTMP协议,所需要的安装文件,安装方式安装: 
./configure --prefix=/etc/nginx   --add-module=./nginx-rtmp-module 
Make 
Make install 

打开防火墙
检查系统的状态和版本:sudo systemctl status nginx 
如果防火墙打开的,需要打开端口 80和443 
打开端口命令 :sudo ufw allow [port]

 

找到nginx 安装的路径下,修改 conf/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_auto_push on;
rtmp {
    server {
        listen 1935;
        chunk_size 4096;
    #ping 30s;
        #notify_method get;

#  直播应用        

application live{  
            live on;
            #record all;
            #record_path /var/www/html/mediaplay/jwplayer/;
            #record_suffix recorded.mp4;
            #allow play all;
            wait_video on;
            #push rtmp://localhost/hefu/live;
    
        }

# 点播配置应用
        application live_one{
             play /tmp/live;
             live on;
             #record off;
        }
    application live_http {
        play http://localhost/live_one;
    }
        application live_two{
    live on;
    #hls on;
    #hls_path /tmp/live;
      #hls_fragment 20s;
      #hls_playlist_length 3000s;
      #hls_cleanup off;
    #idle_streams off;
    #publish_notify on;
    #drop_idle_publisher 70s;
      #record_unique off;
    #record keyframes;  
    #wait_video off;
    #interleave on;
    #wait_key off;
    #record all;
    #record_path  /hefu/live;  
    #record_interval 3600s;
        }
     
       application vod {
               play /tmp/live; 
       }

        application hls{
        live on;
    allow play all;
        hls  on;
        #hls_path  /var/www/html/mediaplay/jwplayer/;
        hls_path  /tmp/live;
        hls_fragment 10s;
    #push rtmp://192.168.1.129:80/hls/test;
        }
    
    }
}

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

    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        #server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
    #下面两个是加上去的,用来配置直播的http访问
        location /stat {    
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
             }
        location /stat.xsl {
        #注意这里的路径不能错误,直接写绝对路径就可以
        root /usr/local/nginx/nginx-rtmp-module/;
        }

        location / {
           root   /var/www/html/;
          index  demo.html index.html index.htm video/index_1.html video5.20/index.html mediaplay/readme.html vide7.5.5/index.html;
        }

location /hls {
        types{
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
        }
        add_header Cache-Control no-cache;
        add_header Access-Control-Allow-Origin *;
        }

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

  
    }

    server {
        listen       80;
        server_name  localhost;

        # rtmp stat
        location /stat {    
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
             }
        location /stat.xsl {
        #注意这里的路径不能错误,直接写绝对路径就可以
        root /usr/local/nginx/nginx-rtmp-module/;
        }

        location hls {
            # Serve HLS fragments
            types {
                application/vnd.apple.mpegurl m3u8;
                video/mp2t ts;
            }
            root /tmp;
            add_header Cache-Control no-cache;
        }
    location /dash {
        # Serve DASH fragments
        root /tmp;
        add_header Cache-Control no-cache;
    }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   /var/html;
        }
    }

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

}

安装完成之后:访问网址http:// [部署nginx服务的IP]/stat 可以看到如下界面  (去掉括号[])

 

nginx +RTMP 下载路径:https://download.youkuaiyun.com/download/qq_19272431/11716691

赞助请扫码:

疑问加微信:

### 安装准备 为了在Ubuntu系统中安装配置支持RTMP协议Nginx服务器,需要先确保系统的更新至最新状态,并安装必要的依赖库。可以使用如下命令来完成这些操作: ```bash sudo apt update && sudo apt upgrade -y sudo apt install build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev -y ``` 上述命令不仅能够保证操作系统处于最新的安全补丁级别,还能一次性安装编译Nginx及其RTMP模块所需的全部开发工具和库文件。 ### 下载与解压源码包 接着下载指定版本的Nginx以及对应的RTMP模块源代码压缩包,并将其解压到合适的位置以便后续编译安装: ```bash cd /tmp/ wget http://nginx.org/download/nginx-1.21.5.tar.gz tar zxf nginx-1.21.5.tar.gz cd nginx-1.21.5/ git clone https://github.com/arut/nginx-rtmp-module.git ../nginx-rtmp-module ``` 这里选择了Nginx 1.21.5作为示例版本号,实际部署时可以根据需求调整具体的版本号码[^1]。 ### 编译前配置 通过`./configure`脚本来设置编译参数,加入对HTTPS的支持以及其他可能需要用到的功能选项。对于本案例而言,则特别指定了要添加来自GitHub仓库克隆下来的RTMP模块路径: ```bash ./configure \ --prefix=/usr/local/nginx \ --with-http_ssl_module \ --add-module=../nginx-rtmp-module ``` 需要注意的是,在某些情况下可能会遇到缺少OpenSSL库而导致配置过程失败的情况。此时应当按照提示信息先行解决依赖关系后再继续尝试运行此步指令。 ### 执行编译与安装 当所有的前置条件都满足之后就可以正式开始编译工作了。考虑到多核处理器的优势,建议采用并行构建的方式来加速整个流程: ```bash make -j$(nproc) sudo make install ``` 这一步骤将会把已经成功编译好的二进制程序及相关资源放置于之前定义的目标目录内(/usr/local/nginx/)。 ### 配置Nginx以启用RTMP功能 创建或编辑位于`/usr/local/nginx/conf/nginx.conf`中的主配置文件,向其中添加针对实时传输控制协议(RTMP)部分的具体设定项。例如: ```nginx rtmp { server { listen 1935; chunk_size 4096; application live { live on; record off; } } } ``` 这段简单的配置允许客户端连接到端口1935并通过名为“live”的应用程序推送直播数据流而不做任何录制动作[^3]。 ### 启动服务并验证 最后启动新安装的服务实例,并确认其正常运作无误: ```bash sudo /usr/local/nginx/sbin/nginx ps aux | grep nginx ``` 如果一切顺利的话应该可以看到至少两个由root用户和其他普通用户分别拥有的进程正在监听HTTP(S)/RTMP请求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值