Skip to content

A self-hosted media server and file management system

feat: improve nginx cache strategy for new image layout

aminnausin0169dbf064d4
diff --git a/docker/etc/nginx/site-opts.d/http.conf b/docker/etc/nginx/site-opts.d/http.conf
index a95eafe3..c7ce6d77 100644
--- a/docker/etc/nginx/site-opts.d/http.conf
+++ b/docker/etc/nginx/site-opts.d/http.conf
@@ -59,12 +59,47 @@ location ~* ^/storage/media/ {
try_files $uri =404;
}
-location ~* ^/storage/.*\.(jpg|jpeg|png|gif|webp|svg|woff|woff2|ttf)$ {
+location ~* ^/storage/.*\.(woff|woff2|ttf)$ {
access_log off;
+ ${securityHeaders}
add_header Cache-Control "private, no-cache";
try_files $uri =404;
}
+# --- storage (images, mixed) ---
+
+location ~* "^/storage/.*_[0-9a-f]{8,}\.(jpg|jpeg|png|gif|webp)$" {
+ access_log off;
+ ${securityHeaders}
+ add_header Cache-Control "public, max-age=31536000, immutable";
+ try_files $uri =404;
+ # 1y (all hashed images so immutable)
+}
+
+location ~* ^/storage/.*/preview\.(webp|png|jpg|jpeg)$ {
+ access_log off;
+ ${securityHeaders}
+ add_header Cache-Control "public, max-age=300";
+ try_files $uri =404;
+ # 5m (external access)
+}
+
+location ~* ^/storage/.*/storyboard/\d+\.(jpg|jpeg|webp)$ {
+ access_log off;
+ ${securityHeaders}
+ add_header Cache-Control "private, max-age=30, must-revalidate";
+ try_files $uri =404;
+ # 5m (allows resets and holds user content information)
+}
+
+location ~* ^/storage/.*\.(jpg|jpeg|png|gif|webp)$ {
+ access_log off;
+ ${securityHeaders}
+ add_header Cache-Control "public, max-age=3600";
+ try_files $uri =404;
+ # 1h (default images or posters)
+}
+
# --- build assets (public, immutable) ---
location ~* \.(js|css|map|woff|woff2|ttf)$ {