wow
Some checks failed
CI / check (push) Has been cancelled
CI / ida (push) Has been cancelled
CI / cpt (push) Has been cancelled
CI / build-nixos (ena) (push) Has been cancelled
CI / build-nixos (hako) (push) Has been cancelled
CI / build-nixos (kazusa) (push) Has been cancelled
CI / build-nixos (mizuki) (push) Has been cancelled
Some checks failed
CI / check (push) Has been cancelled
CI / ida (push) Has been cancelled
CI / cpt (push) Has been cancelled
CI / build-nixos (ena) (push) Has been cancelled
CI / build-nixos (hako) (push) Has been cancelled
CI / build-nixos (kazusa) (push) Has been cancelled
CI / build-nixos (mizuki) (push) Has been cancelled
This commit is contained in:
parent
39d9502143
commit
a8aafeab20
3 changed files with 8 additions and 177 deletions
|
|
@ -1,8 +1,5 @@
|
||||||
{ pkgs, ... }:
|
{ pkgs, ... }:
|
||||||
|
|
||||||
let
|
|
||||||
streamPlayer = pkgs.writeTextDir "index.html" (builtins.readFile ./stream.html);
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
services.caddy = {
|
services.caddy = {
|
||||||
enable = true;
|
enable = true;
|
||||||
|
|
@ -96,22 +93,7 @@ in
|
||||||
'';
|
'';
|
||||||
|
|
||||||
virtualHosts."stream.mizuki.guru".extraConfig = ''
|
virtualHosts."stream.mizuki.guru".extraConfig = ''
|
||||||
handle_path /hls/* {
|
reverse_proxy 127.0.0.1:10023
|
||||||
root * /var/lib/nginx-rtmp/hls
|
|
||||||
header Cache-Control "no-store"
|
|
||||||
file_server
|
|
||||||
}
|
|
||||||
|
|
||||||
handle /live/* {
|
|
||||||
root * ${streamPlayer}
|
|
||||||
rewrite * /index.html
|
|
||||||
file_server
|
|
||||||
}
|
|
||||||
|
|
||||||
handle {
|
|
||||||
root * ${streamPlayer}
|
|
||||||
file_server
|
|
||||||
}
|
|
||||||
'';
|
'';
|
||||||
|
|
||||||
virtualHosts."netbird.mizuki.guru".extraConfig = ''
|
virtualHosts."netbird.mizuki.guru".extraConfig = ''
|
||||||
|
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
<!doctype html>
|
|
||||||
<html lang="ko">
|
|
||||||
<head>
|
|
||||||
<meta charset="utf-8" />
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
||||||
<title>stream.mizuki.guru</title>
|
|
||||||
<style>
|
|
||||||
:root {
|
|
||||||
color-scheme: dark;
|
|
||||||
}
|
|
||||||
body {
|
|
||||||
margin: 0;
|
|
||||||
min-height: 100vh;
|
|
||||||
display: grid;
|
|
||||||
place-items: center;
|
|
||||||
background: #0f0f14;
|
|
||||||
color: #f4f4f5;
|
|
||||||
font-family: system-ui, sans-serif;
|
|
||||||
}
|
|
||||||
main {
|
|
||||||
width: min(100vw - 2rem, 960px);
|
|
||||||
}
|
|
||||||
video {
|
|
||||||
width: 100%;
|
|
||||||
aspect-ratio: 16 / 9;
|
|
||||||
background: #000;
|
|
||||||
border-radius: 12px;
|
|
||||||
}
|
|
||||||
p {
|
|
||||||
color: #a1a1aa;
|
|
||||||
}
|
|
||||||
code {
|
|
||||||
color: #f9a8d4;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<main>
|
|
||||||
<video id="player" controls autoplay playsinline></video>
|
|
||||||
<p id="publish"></p>
|
|
||||||
</main>
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/npm/hls.js@1"></script>
|
|
||||||
<script>
|
|
||||||
const video = document.getElementById("player");
|
|
||||||
const publish = document.getElementById("publish");
|
|
||||||
|
|
||||||
const streamName =
|
|
||||||
decodeURIComponent(
|
|
||||||
location.pathname
|
|
||||||
.replace(/^\/live\/?/, "")
|
|
||||||
.replace(/^\/+|\/+$/g, ""),
|
|
||||||
) || "stream";
|
|
||||||
const source = `/hls/${encodeURIComponent(streamName)}.m3u8`;
|
|
||||||
|
|
||||||
document.title = `${streamName} - stream.mizuki.guru`;
|
|
||||||
publish.innerHTML = `OBS Server: <code>rtmps://stream.mizuki.guru:1935/live</code><br />OBS Stream Key: <code>${escapeHtml(streamName)}</code>`;
|
|
||||||
|
|
||||||
if (video.canPlayType("application/vnd.apple.mpegurl")) {
|
|
||||||
video.src = source;
|
|
||||||
} else if (Hls.isSupported()) {
|
|
||||||
const hls = new Hls({ liveDurationInfinity: true });
|
|
||||||
hls.loadSource(source);
|
|
||||||
hls.attachMedia(video);
|
|
||||||
} else {
|
|
||||||
video.outerHTML =
|
|
||||||
"<p>이 브라우저는 HLS 재생을 지원하지 않습니다.</p>";
|
|
||||||
}
|
|
||||||
|
|
||||||
function escapeHtml(value) {
|
|
||||||
return value.replace(
|
|
||||||
/[&<>"']/g,
|
|
||||||
(ch) =>
|
|
||||||
({
|
|
||||||
"&": "&",
|
|
||||||
"<": "<",
|
|
||||||
">": ">",
|
|
||||||
'"': """,
|
|
||||||
"'": "'",
|
|
||||||
})[ch],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
|
|
@ -1,78 +1,12 @@
|
||||||
{ pkgs, ... }:
|
{ ... }:
|
||||||
|
|
||||||
let
|
|
||||||
domain = "stream.mizuki.guru";
|
|
||||||
hlsDir = "/var/lib/nginx-rtmp/hls";
|
|
||||||
caddyCertDir = "/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/${domain}";
|
|
||||||
in
|
|
||||||
{
|
{
|
||||||
services.nginx = {
|
services.owncast = {
|
||||||
enable = true;
|
enable = true;
|
||||||
package = pkgs.nginx.override {
|
dataDir = "/data/owncast";
|
||||||
modules = [ pkgs.nginxModules.rtmp ];
|
port = 10023;
|
||||||
};
|
listen = "0.0.0.0";
|
||||||
|
openFirewall = true;
|
||||||
appendConfig = ''
|
rtmp-port = 1935;
|
||||||
rtmp {
|
|
||||||
server {
|
|
||||||
listen 127.0.0.1:19350;
|
|
||||||
chunk_size 4096;
|
|
||||||
|
|
||||||
application live {
|
|
||||||
live on;
|
|
||||||
record off;
|
|
||||||
|
|
||||||
hls on;
|
|
||||||
hls_path ${hlsDir};
|
|
||||||
hls_fragment 2s;
|
|
||||||
hls_playlist_length 60s;
|
|
||||||
hls_cleanup off;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.tmpfiles.rules = [
|
|
||||||
"d /var/lib/nginx-rtmp 0755 nginx nginx - -"
|
|
||||||
"d ${hlsDir} 0755 nginx nginx - -"
|
|
||||||
];
|
|
||||||
|
|
||||||
users.users.caddy.extraGroups = [ "nginx" ];
|
|
||||||
|
|
||||||
systemd.services.nginx.serviceConfig.ReadWritePaths = [
|
|
||||||
"/var/lib/nginx-rtmp"
|
|
||||||
];
|
|
||||||
|
|
||||||
systemd.services.stream-stunnel = {
|
|
||||||
description = "RTMPS TLS terminator for stream.mizuki.guru";
|
|
||||||
after = [
|
|
||||||
"network-online.target"
|
|
||||||
"caddy.service"
|
|
||||||
"nginx.service"
|
|
||||||
];
|
|
||||||
wants = [ "network-online.target" ];
|
|
||||||
requires = [ "nginx.service" ];
|
|
||||||
wantedBy = [ "multi-user.target" ];
|
|
||||||
|
|
||||||
serviceConfig = {
|
|
||||||
Type = "simple";
|
|
||||||
User = "caddy";
|
|
||||||
Group = "caddy";
|
|
||||||
ExecStart = "${pkgs.stunnel}/bin/stunnel ${pkgs.writeText "stream-stunnel.conf" ''
|
|
||||||
foreground = yes
|
|
||||||
pid =
|
|
||||||
|
|
||||||
[stream]
|
|
||||||
accept = 0.0.0.0:1935
|
|
||||||
connect = 127.0.0.1:19350
|
|
||||||
cert = ${caddyCertDir}/${domain}.crt
|
|
||||||
key = ${caddyCertDir}/${domain}.key
|
|
||||||
''}";
|
|
||||||
Restart = "always";
|
|
||||||
RestartSec = 5;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
networking.firewall.allowedTCPPorts = [ 1935 ];
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue