我有一个正在直播的流媒体站点,但遇到了一个问题,即完全隐藏了流密钥。我只想到一种解决方法,但是您仍然可以在视图源和Web控制台输出中看到流键:
我唯一想到的选择是使用PHP创建自定义404页面。该查询字符串对于每个用户而言都是唯一的,但不包含用户的流密钥,并将重定向到m3u8文件:
header("Location: /live/source/" . $stream_key . "/index.m3u8");
似乎是个好主意。查看源代码时,您将不再看到流键,但是在控制台中,我仍然得到与上图所示相同的输出。
我正在将nGinx与RTMP和HLS一起使用,并在后端使用PHP。我尝试将hls.min.js和VideoJS用于视频播放器,并获得相同的结果。如果您还有其他选择,请告诉我。如果有办法使用nGinx conf文件严格执行此操作,那么我会百分百尝试。我的nginx.conf文件的内容也在下面。预先感谢!
user root;
worker_processes 2;
events {
worker_connections 2048;
multi_accept on;
}
http {
include mime.types;
server {
listen 80;
listen 443 ssl;
server_name live.xxxxxxxx.tv;
root /home/ubuntu/xxxxxxxx;
ssl_certificate /home/ubuntu/xxxxxxxx/ssl/xxxxxxxx.crt;
ssl_certificate_key /home/ubuntu/xxxxxxxx/ssl/server.key;
location / {
add_header Access-Control-Allow-Origin *;
access_log off;
log_not_found off;
}
location ~ \.php$ {
add_header Access-Control-Allow-Origin *;
try_files $uri =404;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name;
fastcgi_intercept_errors on;
}
error_page 404 = /404.php;
}
}
rtmp {
server {
listen 1935;
buflen 3s;
chunk_size 4096;
max_message 2M;
max_streams 32;
notify_update_timeout 1m;
# on_publish http://api.xxxxxxxx.tv/stream/start;
# on_publish_done http://api.xxxxxxxx.tv/stream/end;
application go {
live on;
access_log off;
hls on;
hls_type live;
hls_fragment 3s;
hls_playlist_length 15s;
hls_nested on;
hls_path /home/ubuntu/xxxxxxxx/live/source;
record all;
record_unique off;
record_interval 5m;
record_suffix .mp4;
record_path /home/ubuntu/xxxxxxxx/archive;
exec_push ffmpeg -i rtmp://live.xxxxxxxx.tv/go/$name -c:v libx264 -c:a copy -s 480x320 rtmp://localhost/live/320p/$name;
}
}
}