mirror of
https://github.com/BluemediaGER/nginx-live.git
synced 2024-11-22 17:55:29 +01:00
Initial commit
This commit is contained in:
commit
de4c9fa992
29
Dockerfile
Normal file
29
Dockerfile
Normal file
|
@ -0,0 +1,29 @@
|
|||
# The Base Image used to create this Image
|
||||
FROM debian:buster-slim
|
||||
|
||||
# Just my name who wrote this file
|
||||
LABEL maintainer="oliver@traber-info.de"
|
||||
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
ENV RTMP_PORT 1935
|
||||
ENV HTTP_PORT 8080
|
||||
|
||||
# Update and install logrotate
|
||||
RUN apt update -y && \
|
||||
apt upgrade -y && \
|
||||
apt autoremove -y && \
|
||||
apt install nginx libnginx-mod-rtmp -y && \
|
||||
apt clean && \
|
||||
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
|
||||
|
||||
# Create users
|
||||
RUN useradd -s /bin/false stunnel && useradd -s /bin/false nginx
|
||||
|
||||
# Copy files into image
|
||||
COPY config/ /template/
|
||||
COPY frontend/ /var/www/html/
|
||||
COPY entrypoint /entrypoint
|
||||
RUN chmod +x /entrypoint && chown -R www-data:www-data /var/www/html/
|
||||
|
||||
ENTRYPOINT ["/entrypoint"]
|
||||
CMD ["/usr/sbin/nginx"]
|
120
config/nginx-ssl.conf.skel
Normal file
120
config/nginx-ssl.conf.skel
Normal file
|
@ -0,0 +1,120 @@
|
|||
# Load RTMP modules
|
||||
load_module "modules/ngx_stream_module.so";
|
||||
load_module "modules/ngx_rtmp_module.so";
|
||||
|
||||
# General configuration
|
||||
daemon off;
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /dev/stdout;
|
||||
pid /var/run/nginx.pid;
|
||||
worker_rlimit_nofile 20960;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
multi_accept on;
|
||||
accept_mutex on;
|
||||
accept_mutex_delay 500ms;
|
||||
use epoll;
|
||||
epoll_events 512;
|
||||
}
|
||||
|
||||
# TLS unwrap
|
||||
stream {
|
||||
upstream backend {
|
||||
server 127.0.0.1:51513;
|
||||
}
|
||||
server {
|
||||
listen {RTMP_PORT} ssl;
|
||||
listen [::]:{RTMP_PORT} ssl;
|
||||
proxy_pass backend;
|
||||
ssl_certificate /cert/{CERT_NAME};
|
||||
ssl_certificate_key /cert/{KEY_NAME};
|
||||
}
|
||||
}
|
||||
|
||||
# RTMP configuration
|
||||
rtmp {
|
||||
server {
|
||||
listen 51513;
|
||||
|
||||
chunk_size 4000;
|
||||
|
||||
application live {
|
||||
live on;
|
||||
|
||||
# Only allow ingest with valid stream key
|
||||
notify_method get;
|
||||
on_publish http://localhost:{HTTP_PORT}/auth;
|
||||
|
||||
# Don't record anything
|
||||
record off;
|
||||
|
||||
# Push stream to HLS endpoint
|
||||
push rtmp://127.0.0.1:51513/hls/live live=1;
|
||||
|
||||
# disable consuming the stream from nginx as rtmp
|
||||
deny play all;
|
||||
}
|
||||
|
||||
application hls {
|
||||
live on;
|
||||
|
||||
# Only allow publishing from local host
|
||||
allow publish 127.0.0.1;
|
||||
deny publish all;
|
||||
|
||||
# disable consuming the stream from nginx as rtmp
|
||||
deny play all;
|
||||
|
||||
# Don't record anything
|
||||
record off;
|
||||
|
||||
# Turn on HLS
|
||||
hls on;
|
||||
hls_path /var/www/html/hls/;
|
||||
hls_fragment 3;
|
||||
hls_playlist_length 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# HTTP configuration
|
||||
http {
|
||||
sendfile off;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
directio 512;
|
||||
|
||||
access_log /dev/stdout;
|
||||
|
||||
server_tokens off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
|
||||
default_type application/octet-stream;
|
||||
|
||||
server {
|
||||
listen {HTTP_PORT};
|
||||
listen [::]:{HTTP_PORT};
|
||||
|
||||
# Check for valid stream key
|
||||
location /auth {
|
||||
if ($arg_name = '{STREAM_KEY}') {
|
||||
return 200;
|
||||
}
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Disable cache
|
||||
add_header 'Cache-Control' 'no-cache';
|
||||
|
||||
root /var/www/html/;
|
||||
index index.html index.htm;
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
}
|
||||
}
|
107
config/nginx.conf.skel
Normal file
107
config/nginx.conf.skel
Normal file
|
@ -0,0 +1,107 @@
|
|||
# Load RTMP modules
|
||||
load_module "modules/ngx_stream_module.so";
|
||||
load_module "modules/ngx_rtmp_module.so";
|
||||
|
||||
# General configuration
|
||||
daemon off;
|
||||
user nginx;
|
||||
worker_processes auto;
|
||||
error_log /dev/stdout;
|
||||
pid /var/run/nginx.pid;
|
||||
worker_rlimit_nofile 20960;
|
||||
|
||||
events {
|
||||
worker_connections 1024;
|
||||
multi_accept on;
|
||||
accept_mutex on;
|
||||
accept_mutex_delay 500ms;
|
||||
use epoll;
|
||||
epoll_events 512;
|
||||
}
|
||||
|
||||
# RTMP configuration
|
||||
rtmp {
|
||||
server {
|
||||
listen {RTMP_PORT};
|
||||
listen [::]:{RTMP_PORT} ipv6only=on;
|
||||
|
||||
chunk_size 4000;
|
||||
|
||||
application live {
|
||||
live on;
|
||||
|
||||
# Only allow ingest with valid stream key
|
||||
notify_method get;
|
||||
on_publish http://localhost:{HTTP_PORT}/auth;
|
||||
|
||||
# Don't record anything
|
||||
record off;
|
||||
|
||||
# Push stream to HLS endpoint
|
||||
push rtmp://127.0.0.1:{RTMP_PORT}/hls/live live=1;
|
||||
|
||||
# disable consuming the stream from nginx as rtmp
|
||||
deny play all;
|
||||
}
|
||||
|
||||
application hls {
|
||||
live on;
|
||||
|
||||
# Only allow publishing from local host
|
||||
allow publish 127.0.0.1;
|
||||
deny publish all;
|
||||
|
||||
# disable consuming the stream from nginx as rtmp
|
||||
deny play all;
|
||||
|
||||
# Don't record anything
|
||||
record off;
|
||||
|
||||
# Turn on HLS
|
||||
hls on;
|
||||
hls_path /var/www/html/hls/;
|
||||
hls_fragment 3;
|
||||
hls_playlist_length 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# HTTP configuration
|
||||
http {
|
||||
sendfile off;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
directio 512;
|
||||
|
||||
access_log /dev/stdout;
|
||||
|
||||
server_tokens off;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
|
||||
default_type application/octet-stream;
|
||||
|
||||
server {
|
||||
listen {HTTP_PORT};
|
||||
listen [::]:{HTTP_PORT};
|
||||
|
||||
# Check for valid stream key
|
||||
location /auth {
|
||||
if ($arg_name = '{STREAM_KEY}') {
|
||||
return 200;
|
||||
}
|
||||
return 404;
|
||||
}
|
||||
|
||||
# Disable cache
|
||||
add_header 'Cache-Control' 'no-cache';
|
||||
|
||||
root /var/www/html/;
|
||||
index index.html index.htm;
|
||||
location / {
|
||||
try_files $uri $uri/ =404;
|
||||
}
|
||||
}
|
||||
}
|
40
entrypoint
Normal file
40
entrypoint
Normal file
|
@ -0,0 +1,40 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Check if the container is started for the first time
|
||||
if [ ! -f /setup.lock ]; then
|
||||
|
||||
# Get valid stream key
|
||||
if [[ ! -z "$STREAM_KEY" ]]; then
|
||||
VALID_STREAM_KEY=$STREAM_KEY
|
||||
else
|
||||
VALID_STREAM_KEY=$(tr -dc A-Za-z0-9 </dev/urandom | head -c 48)
|
||||
echo "Your auto-generated stream key is: $VALID_STREAM_KEY"
|
||||
fi
|
||||
|
||||
# Build nginx.conf
|
||||
cp /template/nginx.conf.skel /etc/nginx/nginx.conf
|
||||
|
||||
# Check if tls should be enabled
|
||||
if [[ ! -z "$TLS_CERT" ]]; then
|
||||
# Build nginx.conf for RTMPS
|
||||
cp /template/nginx-ssl.conf.skel /etc/nginx/nginx.conf
|
||||
sed -i "s/{CERT_NAME}/$TLS_CERT/g" /etc/nginx/nginx.conf
|
||||
sed -i "s/{KEY_NAME}/$TLS_KEY/g" /etc/nginx/nginx.conf
|
||||
else
|
||||
# nginx.conf without ssl
|
||||
cp /template/nginx.conf.skel /etc/nginx/nginx.conf
|
||||
fi
|
||||
|
||||
# Complete nginx config
|
||||
sed -i "s/{RTMP_PORT}/$RTMP_PORT/g" /etc/nginx/nginx.conf
|
||||
sed -i "s/{STREAM_KEY}/$VALID_STREAM_KEY/g" /etc/nginx/nginx.conf
|
||||
sed -i "s/{HTTP_PORT}/$HTTP_PORT/g" /etc/nginx/nginx.conf
|
||||
|
||||
# Touch setup lock
|
||||
touch /setup.lock
|
||||
|
||||
fi
|
||||
|
||||
echo "Init done. Starting nginx..."
|
||||
|
||||
exec "$@"
|
BIN
frontend/assets/backdrop.jpg
Normal file
BIN
frontend/assets/backdrop.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 104 KiB |
24
frontend/assets/css/style.css
Normal file
24
frontend/assets/css/style.css
Normal file
|
@ -0,0 +1,24 @@
|
|||
body{
|
||||
margin: 0;
|
||||
font-family: sans-serif;
|
||||
}
|
||||
.container{
|
||||
max-width: 1400px;
|
||||
margin: 0 10px;
|
||||
}
|
||||
|
||||
@media (min-width: 1024px) {
|
||||
.container{
|
||||
width: 70%;
|
||||
margin: 0 auto;
|
||||
}
|
||||
}
|
||||
|
||||
#player > [data-player] {
|
||||
padding-bottom: 56.25%;
|
||||
height: auto !important;
|
||||
}
|
||||
#player > .fullscreen[data-player] {
|
||||
padding-bottom: 0;
|
||||
height: 100% !important;
|
||||
}
|
BIN
frontend/assets/favicon.ico
Normal file
BIN
frontend/assets/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
1144
frontend/assets/js/player.js
Normal file
1144
frontend/assets/js/player.js
Normal file
File diff suppressed because one or more lines are too long
36
frontend/index.html
Normal file
36
frontend/index.html
Normal file
|
@ -0,0 +1,36 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Livestream</title>
|
||||
<link rel="icon" href="assets/favicon.ico">
|
||||
<link rel="stylesheet" href="assets/css/style.css">
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1>Start watching</h1>
|
||||
<p>Click on the play button to start watching. If you see an error, the stream is not live yet. In this case, try again a little later.</p>
|
||||
|
||||
<div id="player"></div>
|
||||
</div>
|
||||
</body>
|
||||
<script src="assets/js/player.js"></script>
|
||||
<script>
|
||||
// expose Clappr to load additional plugins
|
||||
window.Clappr = window.VOCPlayer
|
||||
</script>
|
||||
<script>
|
||||
new VOCPlayer.Player({
|
||||
|
||||
//** Standard clappr.io Options **
|
||||
// Use custom source
|
||||
sources: ["hls/live.m3u8"],
|
||||
|
||||
// Set a custom poster
|
||||
poster: "assets/backdrop.jpg",
|
||||
|
||||
// Assign parent by id
|
||||
parentId: "#player"
|
||||
})
|
||||
</script>
|
||||
</html>
|
Loading…
Reference in a new issue