因为nginx-rtmp-flv模块使用的不是http2.0,故大部分浏览器和nginx交互的时候,会因为并发数量的限制,导致最多只能六路并行。
也就是flv.js从同一个端口只能获取六路视频,多了就会交互失败。此时有多个解决方案:
1.有说联系nginx-rtmp-flv的作者,使用商业版带有http2.0。
2.有说修改浏览器配置,但是各个浏览器不是都可以修改的。
3.有说使用websocket替代http的,但是既有的方案未必支持更改。
4.有说使用反向代理,做几个新端口,代理一下原先的端口,做一个转发,这个方案是配置简单,但是由于转发次数过多,消耗了流量,并发量大的时候会卡断的。(参照https://blog.csdn.net/weixin_38238552/article/details/118379672)
我们可以监听多个http端口:
6900、6901、6902
server {
listen 6900;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers '*';
}
location /live {
flv_live on;
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
add_header Access-Control-Allow-Headers '*';
}
location /stat {
#configuration of push & pull status
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root html; #specify in where stat.xsl located
}
#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 6901;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers '*';
}
location /live {
flv_live on;
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
add_header Access-Control-Allow-Headers '*';
}
location /stat {
#configuration of push & pull status
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root html; #specify in where stat.xsl located
}
#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 6902;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
root html;
index index.html index.htm;
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, POST, OPTIONS';
add_header Access-Control-Allow-Headers '*';
}
location /live {
flv_live on;
chunked_transfer_encoding on; #open 'Transfer-Encoding: chunked' response
add_header 'Access-Control-Allow-Origin' '*'; #add additional HTTP header
add_header 'Access-Control-Allow-Credentials' 'true'; #add additional HTTP header
add_header Access-Control-Allow-Headers '*';
}
location /stat {
#configuration of push & pull status
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root html; #specify in where stat.xsl located
}
#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;
}
}
火狐浏览器实测有效,原先无法打开的第七、第八、第九路打开了,并且经过测试,稳定性也高于反向代理。(下边这种配置方式为反向代理)