当前正在尝试在我的NGINX中实现HLS。我正在尝试在浏览器中打开流。我还在流中使用“拉”,所以我将重新流化当前无法正常工作的RTMP源。
我的nginx配置文件
user www-data;
worker_processes auto;
events {
worker_connections 1024;
}
# RTMP configuration
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
pull rtmp://<STREAM_PULL_IP_ADDR>:1935/rtplive live=1;
# Turn on HLS
hls on;
hls_path /tmp/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp/;
}
}
}
显示流的网站:
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Live Streaming</title>
<link href="//vjs.zencdn.net/5.8/video-js.min.css" rel="stylesheet">
<script src="//vjs.zencdn.net/5.8/video.min.js"></script>
</head>
<body>
<video id="player" class="video-js vjs-default-skin" height="360" width="640" controls preload="none">
<source src="http://<MY_IP_ADDR>:8080/hls/stream.m3u8" type="application/x-mpegURL" />
</video>
<script>
var player = videojs('#player');
</script>
</body>
</html>
我也无法使用/hls/stream.m3u8调用我的URL,因为它以nginx错误结尾:
28654#0: *2 open() "/tmp/hls/stream.m3u8" failed (2: No such file or directory), client: <VISITOR_IP>, server: , request: "GET /hls/stream.m3u8 HTTP/1.1"
网站代码由托管在同一服务器上的apache2提供。我认为这不是问题,因为stream.m3u8网址会导致NGINX错误。因此可以在NGINX环境中调用该URL。
更新:
直接调用nginx URL(/ hls)后,错误日志将输出:
31872#0: *4 directory index of "/tmp/hls/" is forbidden, client: <VISITOR_IP_ADDR>, server:
,但该目录具有www-data的权限1777,这是nginx用户。