提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档


文章目录

  • 前言
  • 一、nginx-rtmp-module-master
  • 二、使用步骤
  • 1.我的ngix版本1.9.9
  • 2.注意



前言

由于业务需要点播功能我随手记了一下基本的环境配置。这个是用服务器直接用宝塔面板搞得,配置起来还是比较简单的。另外一个是没有用宝塔面板配置的笔记,过程比较繁琐,有时间再整理一下。


一、nginx-rtmp-module-master

这个是用nginx搭建流媒体服务器必备nginx插件,直接下载
链接:https://pan.baidu.com/s/1gbq4vQbXvbz4rmShhgc_ew
提取码:4i35

二、使用步骤

1.我的ngix版本1.9.9

(1)将文件传到linux 的/www/server下运行解压命令

unzip master.zip

宝塔添加nginx为编译安装(勾选后生效)

模块参数 --add-module=/www/server/nginx-rtmp-module-master

自己搭建流媒体服务器 python 如何搭建流媒体服务器_html

图片里是我后来自己截的图,还是按照

自己搭建流媒体服务器 python 如何搭建流媒体服务器_Access_02


这是我的配置文件

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 51200;
        multi_accept on;
    }
# 新增 start
rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        #rtmp协议推流
        application live {
             live on;
              record all;
            record_path /tmp/video; # 保存路径
            #  record_max_size 1K;
             # append current timestamp to each flv
             record_unique on;
            #  # publish only from localhost
            #  allow publish 127.0.0.1;
            #  deny publish all;
 
        }
         # HLS直播流		
       application hls {
             #limit_rate_after 1m;
             #limit_rate 500k;  
             live on;  
             hls on;  
             hls_path /tmp/hls;
             hls_fragment 8s;             #用来设置每一个块的大小。默认是5秒。只能为整数
             hls_playlist_length 3s;    #设置播放列表的长度,单位是秒
             hls_nested on;              #默认是off。打开后的作用是每条流自己有一个文件夹
             hls_cleanup off;            #不清理ts	, on|off 默认是开着的,是否删除列表中已经没有的媒体块
             #hls_continuous:             #on|off 设置连续模式,是从停止播放的点开始还是直接跳过
			 
       }
	   
        # hls on;
        # hls_path E:/tmp/hls;
        # hls_fragment 5s;#没有生效
        # hls_playlist_length 30s;
        # hls_nested on; #默认是off。打开后的作用是每条流自己有一个文件夹
        # hls_cleanup off;#不清理ts
	   
    }
}
# 新增end
http
    {
        include       mime.types;
		#include luawaf.conf;

		include proxy.conf;

        default_type  application/octet-stream;

        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;
    }
    
        server {
        listen       8088; # 端口我改成了 8088, 因为我的80端口被占用了
        server_name  localhost;

#后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问		
		location ^~ /jeecg-boot {
			proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
			proxy_set_header        Host 127.0.0.1;
			proxy_set_header        X-Real-IP $remote_addr;
			proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
		}
        
         #修改start
         location / {
             root html;
             index  index.html index.htm; 
			 
            add_header Access-Control-Allow-Origin *; # 配置跨域
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
            if (!-e $request_filename) {
				rewrite ^(.*)$ /index.html?s=$1 last;
				break;
			}
			
         }
		location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root nginx-rtmp-module/;
        }
        location /control {
            rtmp_control all;
        }

		location /rtmp-publisher {
             root nginx-rtmp-module/test;
        }
		#加入hls支持(这是新增的哈)
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8; 
                #或 application/x-mpegURL
                video/mp2t ts;
            }
            alias /tmp/hls;  #视频流文件目录(自己创建)
            expires -1;
            add_header Cache-Control no-cache; #跨域支持,不然网页播放不了
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
        }
        #修改end
        #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; # single backend process
        #    fastcgi_pass   myLoadBalancer; # or multiple, see example above
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  $document_root$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;
        #}
    }

    server {
        listen       8089; # 端口我改成了 8088, 因为我的80端口被占用了
        server_name  localhost;
		
		#后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问		
		location ^~ /jeecg-boot {
			proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
			proxy_set_header        Host 127.0.0.1;
			proxy_set_header        X-Real-IP $remote_addr;
			proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
		}
		
         #修改start
         location / {
             root dist;
             index  index.html index.htm; 
			 
            add_header Access-Control-Allow-Origin *; # 配置跨域
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
			if (!-e $request_filename) {
				rewrite ^(.*)$ /index.html?s=$1 last;
				break;
			}
         }
		 
		
       
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        
    }
    
    
include /www/server/panel/vhost/nginx/*.conf;
}

配置文件核心部分

# 新增 start
rtmp {
    server {
        listen 1935;
        chunk_size 4000;
        #rtmp协议推流
        application live {
             live on;
              record all;
            record_path /tmp/video; # 保存路径
            #  record_max_size 1K;
             # append current timestamp to each flv
             record_unique on;
            #  # publish only from localhost
            #  allow publish 127.0.0.1;
            #  deny publish all;
 
        }
         # HLS直播流		
       application hls {
             #limit_rate_after 1m;
             #limit_rate 500k;  
             live on;  
             hls on;  
             hls_path /tmp/hls;
             hls_fragment 8s;             #用来设置每一个块的大小。默认是5秒。只能为整数
             hls_playlist_length 3s;    #设置播放列表的长度,单位是秒
             hls_nested on;              #默认是off。打开后的作用是每条流自己有一个文件夹
             hls_cleanup off;            #不清理ts	, on|off 默认是开着的,是否删除列表中已经没有的媒体块
             #hls_continuous:             #on|off 设置连续模式,是从停止播放的点开始还是直接跳过
			 
       }
	   
        # hls on;
        # hls_path E:/tmp/hls;
        # hls_fragment 5s;#没有生效
        # hls_playlist_length 30s;
        # hls_nested on; #默认是off。打开后的作用是每条流自己有一个文件夹
        # hls_cleanup off;#不清理ts
	   
    }
}
# 新增end

        server {
        listen       8088; # 端口我改成了 8088, 因为我的80端口被占用了
        server_name  localhost;

#后台服务配置,配置了这个location便可以通过http://域名/jeecg-boot/xxxx 访问		
		location ^~ /jeecg-boot {
			proxy_pass              http://127.0.0.1:8080/jeecg-boot/;
			proxy_set_header        Host 127.0.0.1;
			proxy_set_header        X-Real-IP $remote_addr;
			proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
		}
        
         #修改start
         location / {
             root html;
             index  index.html index.htm; 
			 
            add_header Access-Control-Allow-Origin *; # 配置跨域
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
            if (!-e $request_filename) {
				rewrite ^(.*)$ /index.html?s=$1 last;
				break;
			}
			
         }
		location /stat {
            rtmp_stat all;
            rtmp_stat_stylesheet stat.xsl;
        }
        location /stat.xsl {
            root nginx-rtmp-module/;
        }
        location /control {
            rtmp_control all;
        }

		location /rtmp-publisher {
             root nginx-rtmp-module/test;
        }
		#加入hls支持(这是新增的哈)
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8; 
                #或 application/x-mpegURL
                video/mp2t ts;
            }
            alias /tmp/hls;  #视频流文件目录(自己创建)
            expires -1;
            add_header Cache-Control no-cache; #跨域支持,不然网页播放不了
            add_header Access-Control-Allow-Origin *;
            add_header Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept";
            add_header Access-Control-Allow-Methods "GET, POST, OPTIONS";
        }
        #修改end
        #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; # single backend process
        #    fastcgi_pass   myLoadBalancer; # or multiple, see example above
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  $document_root$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;
        #}
    }

2.注意

注意
alias /tmp/hls; #视频流文件目录(自己创建) 这个文件夹需要提前创建不然转码的时候会报错