宝塔Nginx集成PingOS,打造自己的直播服务器

提醒:本文最后更新于 2024-10-11 01:49,文中所关联的信息可能已发生改变,请知悉!

PingOS 在宝塔面板 Nginx1.22.0 上编译成功,理论上 Nginx1.22.0 以下版本都可以成功编译。PingOS 共有 5 个模块,下面进行模块集成:

集成编译 PingOS 模块

登陆宝塔面板—> 软件商店—> 运行环境—>Nginx—> 安装

宝塔 Nginx 集成 PingOS,打造自己的直播服务器

安装版本 nginx1.22 —> 安装方式 编译安装 —> 点击 添加自定义模块 键钮

宝塔 Nginx 集成 PingOS,打造自己的直播服务器

编辑自定义选装模块参数

宝塔 Nginx 集成 PingOS,打造自己的直播服务器
模块名称: nginx_rtmp_module
模块参数: --add-module=/www/server/modules/nginx_rtmp_module
前置脚本: git clone https://github.com/huxubo/nginx-rtmp-module.git /www/server/modules/nginx_rtmp_module

模块名称: nginx_client_module
模块参数: --add-module=/www/server/modules/nginx_client_module
前置脚本: git clone https://github.com/huxubo/nginx-client-module.git /www/server/modules/nginx_client_module

模块名称: nginx_multiport_module
模块参数: --add-module=/www/server/modules/nginx_multiport_module
前置脚本: git clone https://github.com/huxubo/nginx-multiport-module.git /www/server/modules/nginx_multiport_module

模块名称: nginx_toolkit_module
模块参数: --add-module=/www/server/modules/nginx_toolkit_module
前置脚本: git clone https://github.com/huxubo/nginx-toolkit-module.git /www/server/modules/nginx_toolkit_module

模块名称: nginx_ts_module
模块参数: --add-module=/www/server/modules/nginx_ts_module
前置脚本: git clone https://github.com/huxubo/nginx-ts-module.git /www/server/modules/nginx_ts_module

添加完模块后点提交进行编译安装

宝塔 Nginx 集成 PingOS,打造自己的直播服务器

添加站点,修改 Nginx 配置

用以下代码替换 /www/server/nginx/conf/nginx.conf

user  www www;
worker_processes auto;
error_log  /www/wwwlogs/nginx_error.log  crit;
pid        /www/server/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200;

stream {
    log_format tcp_format '$time_local|$remote_addr|$protocol|$status|$bytes_sent|$bytes_received|$session_time|$upstream_addr|$upstream_bytes_sent|$upstream_bytes_received|$upstream_connect_time';
  
    access_log /www/wwwlogs/tcp-access.log tcp_format;
    error_log /www/wwwlogs/tcp-error.log;
    include /www/server/panel/vhost/nginx/tcp/*.conf;
}

events {
    use epoll;
    worker_connections  65535;
    multi_listen unix:/tmp/http 80;
    multi_listen unix:/tmp/rtmp 1935;

    dynamic_refresh_interval 5s;
    dynamic_domain_buckets   1001;
    resolver 114.114.114.114  valid=1m;
    resolver_timeout 30s;
}

rtmp {log_format log_bandwidth '{"app":"$app","name":"$name","bitrate":$bitrate,"args":"$args","timestamp":$ntp,"ts":"$time_local","type":"$command","remote_addr":"$remote_addr","domain":"$domain"}';
    access_log logs/bandwidth.log log_bandwidth trunc=60s;

    server {
        listen 1935;
        listen [::]:1935 ipv6only=on;
        serverid 000;
        out_queue 10240;
        server_name push.bailu.ml;
        rtmp_auto_pull on;
        rtmp_auto_pull_port unix:/tmp/rtmp;
   
        application push {
            live on;
            push rtmp://127.0.0.1/live app=live;
        }

        application live {
           live_record off;
           live_record_path /data/record;

            recorder r1{
                record off;
                record_path /data/record;
            }

            live on;
            hls on;
            hls_path /tmp/hls;
            hls_fragment 4000ms;
            # hls_max_fragment 10000ms;
            hls_playlist_length 12000ms;
            hls_type live;

            hls2 off;
            mpegts_cache_time 20s;

            hls2_fragment 2000ms;
            hls2_max_fragment 3000ms;
            hls2_playlist_length 6000ms;

            wait_key on;
            wait_video on;
            cache_time 1s;
            send_all on;
            low_latency off;
             
            # h265 codecid, default 12
            hevc_codecid  12;
        }
    }
}

http
    {
        include       mime.types;
        #include luawaf.conf;

        include proxy.conf;

        default_type  application/octet-stream;

        log_format  main1  '$remote_addr - $remote_user [$time_local]"$request"''$status $body_bytes_sent "$http_referer" ''"$http_user_agent""$http_X-Forwarded-For" "$http_X-Real-IP" "$host"';


        map $HTTP_CF_CONNECTING_IP  $clientRealIp {
            ""    $remote_addr;
            ~^(?P<firstAddr>[\w:|.]+),?.*$    $firstAddr;
        }

        log_format  main  '$clientRealIp|[$time_local]| 来源:"$http_referer"| 请求:"$request"| 状态:"$status"|UA:"$http_user_agent"| 远程 IP: [$remote_addr]';

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

        sendfile   on;
        tcp_nopush on;

        keepalive_timeout 60;

        tcp_nodelay on;

        fastcgi_connect_timeout 300;
        fastcgi_send_timeout 300;
        fastcgi_read_timeout 300;
        fastcgi_buffer_size 64k;
        fastcgi_buffers 4 64k;
        fastcgi_busy_buffers_size 128k;
        fastcgi_temp_file_write_size 256k;
        fastcgi_intercept_errors on;

        gzip on;
        gzip_min_length  1k;
        gzip_buffers     4 16k;
        gzip_http_version 1.1;
        gzip_comp_level 2;
        gzip_types     text/plain application/javascript application/x-javascript text/javascript text/css application/xml;
        gzip_vary on;
        gzip_proxied   expired no-cache no-store private auth;
        gzip_disable   "MSIE [1-6]\.";

        limit_conn_zone $binary_remote_addr zone=perip:10m;
        limit_conn_zone $server_name zone=perserver:10m;

        server_tokens off;
        access_log off;

server
    {
        listen 888;
        server_name phpmyadmin;
        index index.html index.htm index.php;
        root  /www/server/phpmyadmin;

        #error_page   404   /404.html;
        include enable-php.conf;

        location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
        {expires      30d;}

        location ~ .*\.(js|css)?$
        {expires      12h;}

        location ~ /\.
        {deny all;}

        access_log  /www/wwwlogs/access.log;
    }
include /www/server/panel/vhost/nginx/*.conf;
}

添加站点,并修改配置文件

宝塔 Nginx 集成 PingOS,打造自己的直播服务器

在配置文件中添加以下代码

    location /rtmp_stat {
        rtmp_stat all;
        rtmp_stat_stylesheet /stat.xsl;
    }

    location /xstat {rtmp_stat all;}

    location /sys_stat {sys_stat;}

    location /sys_stat_proxy/ {rewrite ^/proxy/(.*) /sys_stat break;
            proxy_pass http://$1:;
    }

    location /bs {
        broadcast unix:/tmp/http /sys_stat_proxy;
        broadcast_rewrite_prefix " " [;
        broadcast_suffix ];
    }

    location ~ .mp4$ {
        root html;
        # mp4;
    }

    location /control {rtmp_control all;}

    # location /flv {
    #     flv_live 1935 app=live;
    #     chunked_transfer_encoding off;
    # }

    location /ts {
        ts_live 1935 app=live;
        expires -1;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header "Access-Control-Allow-Methods" "*";
        add_header "Access-Control-Allow-Headers" "Content-Type,Access-Token";
        add_header "Access-Control-Expose-Headers" "*";
    }
    
    location /hls {
        # Serve HLS fragments
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        root /tmp;
        expires -1;
        add_header Cache-Control no-cache;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header "Access-Control-Allow-Credentials" "true";
        add_header "Access-Control-Allow-Methods" "*";
        add_header "Access-Control-Allow-Headers" "Content-Type,Access-Token";
        add_header "Access-Control-Expose-Headers" "*";
    }

上传文件至站点根目录

宝塔 Nginx 集成 PingOS,打造自己的直播服务器

搞定收工

宝塔 Nginx 集成 PingOS,打造自己的直播服务器
正文完
 1
簡單
版权声明:本站原创文章,由 簡單 于2022-10-19发表,共计5457字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。