Files
easy-stream/infra/nginx/default.conf.template
T
2026-07-14 12:51:36 +03:30

119 lines
3.8 KiB
Plaintext

map $uri $media_cache_control {
default "no-store";
~*\.m3u8$ "private, no-cache, no-store, must-revalidate";
# Safe origin default: browsers may retain immutable generation assets, but a
# shared CDN must not cache them until it enforces playback authorization at
# the edge before cache lookup.
~*\.(m4s|mp4|vtt|ass|ttf|otf)$ "private, max-age=31536000, immutable";
}
upstream easy_stream_api {
server api:3000;
keepalive 64;
}
server {
listen 8080;
server_name _;
server_tokens off;
root /usr/share/nginx/html;
include /etc/nginx/security-headers.conf;
# Cache bookkeeping is mounted beside public generations but is never media.
location ~ (^|/)\. {
deny all;
}
location /api/ {
proxy_http_version 1.1;
proxy_set_header Host $host;
# Never trust a client-supplied forwarding chain. Configure real_ip_from
# for the selected CDN at deployment time if end-user IPs are required.
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://easy_stream_api;
add_header Cache-Control "no-store" always;
include /etc/nginx/security-headers.conf;
}
location = /_media_auth {
internal;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_set_header Cookie $http_cookie;
proxy_set_header X-Media-Auth-Secret "${MEDIA_AUTH_SHARED_SECRET}";
proxy_pass http://easy_stream_api/internal/media-auth;
}
# Offline compatibility encodes are durable and live on a separate disk.
# Keep the more-specific prefix ahead of the bounded JIT cache route.
location /media/derived/ {
auth_request /_media_auth;
alias /srv/easy-stream/derived/;
disable_symlinks on;
types {
application/vnd.apple.mpegurl m3u8;
video/iso.segment m4s;
video/mp4 mp4;
text/vtt vtt;
text/x-ssa ass;
font/ttf ttf;
font/otf otf;
}
add_header Cache-Control $media_cache_control always;
include /etc/nginx/security-headers.conf;
}
location /media/ {
auth_request /_media_auth;
alias /srv/easy-stream/cache/;
disable_symlinks on;
types {
application/vnd.apple.mpegurl m3u8;
video/iso.segment m4s;
video/mp4 mp4;
text/vtt vtt;
text/x-ssa ass;
font/ttf ttf;
font/otf otf;
}
add_header Cache-Control $media_cache_control always;
include /etc/nginx/security-headers.conf;
}
# TMDB artwork stays same-origin for CSP/COEP and can be cached by the outer CDN.
location /images/tmdb/ {
limit_except GET HEAD { deny all; }
rewrite ^/images/tmdb/(w500|w1280)(/.*)$ /t/p/$1$2 break;
proxy_ssl_server_name on;
proxy_ssl_verify on;
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
proxy_ssl_verify_depth 3;
proxy_set_header Host image.tmdb.org;
proxy_hide_header Set-Cookie;
proxy_hide_header Cache-Control;
proxy_pass https://image.tmdb.org;
add_header Cache-Control "public, max-age=86400, stale-while-revalidate=604800" always;
include /etc/nginx/security-headers.conf;
}
location /healthz {
access_log off;
return 200 "ok\n";
}
location /assets/ {
try_files $uri =404;
add_header Cache-Control "public, max-age=31536000, immutable" always;
include /etc/nginx/security-headers.conf;
}
location / {
try_files $uri $uri/ /index.html;
add_header Cache-Control "no-cache";
include /etc/nginx/security-headers.conf;
}
}