Files
nginx-hls/config/nginx.conf.template
T
2026-09-27 15:55:38 +08:00

196 lines
7.5 KiB
Plaintext

worker_processes auto;
error_log /dev/stderr warn;
pid /tmp/nginx.pid;
events {
worker_connections 1024;
}
thread_pool vod_io threads=2 max_queue=65536;
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format vod '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" rt=$request_time';
access_log /dev/stdout vod;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
server_tokens off;
aio threads=vod_io;
upstream catalog_backend {
server catalog:8081;
}
server {
listen 8080;
server_name _;
autoindex off;
vod_mode local;
vod_metadata_cache metadata_cache 64m;
vod_response_cache response_cache 16m;
vod_open_file_thread_pool vod_io;
open_file_cache max=1000 inactive=30s;
open_file_cache_valid 30s;
open_file_cache_min_uses 1;
open_file_cache_errors on;
location = /healthz {
access_log off;
default_type text/plain;
return 200 "ok\n";
}
location ^~ /hls/ {
alias /media/;
vod hls;
vod_segment_duration 6000;
vod_align_segments_to_key_frames on;
vod_manifest_segment_durations_mode accurate;
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Expose-Headers "Accept-Ranges, Content-Length, Content-Range, Content-Type" always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Max-Age 600 always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
return 204;
}
if ($request_method !~ ^(GET|HEAD)$) {
return 405;
}
}
location = /api/media {
proxy_pass http://catalog_backend;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_hide_header Cache-Control;
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Expose-Headers "Content-Length, Content-Type" always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Max-Age 600 always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
return 204;
}
if ($request_method !~ ^(GET|HEAD)$) {
return 405;
}
}
location = /api/media/status {
proxy_pass http://catalog_backend;
proxy_set_header Host $host;
proxy_hide_header Cache-Control;
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Expose-Headers "Content-Length, Content-Type" always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Max-Age 600 always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
return 204;
}
if ($request_method !~ ^(GET|HEAD)$) {
return 405;
}
}
location = /api/media/rescan {
proxy_pass http://catalog_backend;
proxy_set_header Host $host;
proxy_hide_header Cache-Control;
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Expose-Headers "Content-Length, Content-Type" always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "POST, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Max-Age 600 always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
return 204;
}
if ($request_method != POST) {
return 405;
}
}
location ^~ /api/media/covers/ {
proxy_pass http://catalog_backend;
proxy_set_header Host $host;
proxy_hide_header Cache-Control;
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Expose-Headers "Content-Length, Content-Type" always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
if ($request_method = OPTIONS) {
add_header Access-Control-Allow-Origin "${PLAYER_ORIGIN}" always;
add_header Access-Control-Allow-Methods "GET, HEAD, OPTIONS" always;
add_header Access-Control-Allow-Headers "Origin, Range, Accept, Content-Type" always;
add_header Access-Control-Max-Age 600 always;
add_header Cache-Control "no-store" always;
add_header Vary "Origin" always;
return 204;
}
if ($request_method !~ ^(GET|HEAD)$) {
return 405;
}
}
location / {
return 404;
}
}
}