Dispatcharr/docker/nginx.conf
SergeantPanda 5c9221e755 feat(epg): Enhance Schedules Direct poster handling with caching and proxy improvements
This commit improves the Schedules Direct poster fetching mechanism by implementing a caching strategy for SD program posters using nginx, with a 14-day cache duration. It introduces a cache-busting feature that appends a hash of the SD icon URI to the poster URL, ensuring clients receive updated artwork without stale images. Additionally, the code structure has been refined to separate poster proxy logic into dedicated utility functions, enhancing maintainability. Tests have been added to verify the correct behavior of the new caching and proxy functionalities.
2026-07-21 18:37:57 +00:00

102 lines
3.1 KiB
Nginx Configuration File

# Channel/VOD logos and SD program posters share /data/cache/ with separate zones.
proxy_cache_path /data/cache/logos levels=1:2 keys_zone=logo_cache:10m
inactive=24h use_temp_path=off;
proxy_cache_path /data/cache/sd_posters levels=1:2 keys_zone=sd_poster_cache:10m
inactive=14d use_temp_path=off;
server {
listen NGINX_PORT;
listen [::]:NGINX_PORT;
proxy_connect_timeout 75;
proxy_send_timeout 300;
proxy_read_timeout 300;
client_max_body_size 0;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $host:$server_port;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# Serve Django via uWSGI
location / {
include uwsgi_params;
uwsgi_pass unix:/app/uwsgi.sock;
}
location /assets/ {
root /app/static;
}
location /static/ {
root /app;
}
location /logos/ {
root /data;
}
# Internal location for X-Accel-Redirect backup downloads
# Django handles auth, nginx serves the file directly
location /protected-backups/ {
internal;
alias /data/backups/;
}
location ~ ^/api/channels/logos/(?<logo_id>\d+)/cache/ {
proxy_pass http://127.0.0.1:5656;
proxy_cache logo_cache;
proxy_cache_key "$scheme$request_uri"; # Cache per logo URL
proxy_cache_valid 200 24h; # Cache for 24 hours
proxy_cache_use_stale error timeout updating; # Serve stale if Django is slow
}
location ~ ^/api/vod/vodlogos/(?<logo_id>\d+)/cache/ {
proxy_pass http://127.0.0.1:5656;
proxy_cache logo_cache;
proxy_cache_key "$scheme$request_uri"; # Cache per logo URL
proxy_cache_valid 200 24h; # Cache for 24 hours
proxy_cache_use_stale error timeout updating; # Serve stale if Django is slow
}
# SD program posters: 14d nginx cache. Clients pass ?v=<hash of sd_icon>
location ~ ^/api/epg/programs/(?<prog_id>\d+)/poster/ {
proxy_pass http://127.0.0.1:5656;
proxy_cache sd_poster_cache;
proxy_cache_key "$scheme$request_uri";
proxy_cache_valid 200 14d;
proxy_cache_use_stale error timeout updating;
}
# admin disabled when not in dev mode
location ~ ^/admin/?$ {
return 301 /login;
}
# Route HDHR request to Django
location /hdhr {
include uwsgi_params;
uwsgi_pass unix:/app/uwsgi.sock;
}
# WebSockets for real-time communication
location /ws/ {
proxy_pass http://127.0.0.1:8001;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
# Route TS proxy requests to the dedicated instance
location /proxy/ {
include uwsgi_params;
uwsgi_pass unix:/app/uwsgi.sock;
uwsgi_buffering off;
uwsgi_read_timeout 300s;
uwsgi_send_timeout 300s;
client_max_body_size 0;
}
}