From 295d1751b1c1bb1e8abd5fda3c003b5a77a2f082 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 13 Apr 2024 00:07:03 +0200 Subject: [PATCH 1/4] banners.php: make banners redirect instead of serving the image directly --- banners.php | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/banners.php b/banners.php index ef75c2cb..f08d3b03 100644 --- a/banners.php +++ b/banners.php @@ -1,16 +1,8 @@ \ No newline at end of file +$filename = $files[array_rand($files)]; +header("Location: /banners/$filename", true, 307); +header('Cache-Control: no-cache'); From 05952a6222943b084a1d5131bdfbceaa4fc60229 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 13 Apr 2024 12:22:32 +0200 Subject: [PATCH 2/4] docker: add banners/ directory to directories to copy over --- docker/php/bootstrap.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/php/bootstrap.sh b/docker/php/bootstrap.sh index e94dcf28..131a7000 100755 --- a/docker/php/bootstrap.sh +++ b/docker/php/bootstrap.sh @@ -25,7 +25,6 @@ fi # Link the entrypoints from the exposed directory. ln -nfs \ - /code/banners/ \ /code/tools/ \ /code/walls/ \ /code/*.php \ @@ -36,6 +35,7 @@ ln -nfs \ # Static files accessible from the webserver must be copied. cp -ur /code/static /var/www/ cp -ur /code/stylesheets /var/www/ +cp -ur /code/banners /var/www/ # Ensure correct permissions are set, since this might be bind mount. chown www-data /var/www From c09a85ca65448926f39538d81523424ceb7ba342 Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 13 Apr 2024 12:27:56 +0200 Subject: [PATCH 3/4] docker: fix nginx site config --- docker/nginx/leftypol.conf | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/docker/nginx/leftypol.conf b/docker/nginx/leftypol.conf index cdb28076..83f8b10a 100644 --- a/docker/nginx/leftypol.conf +++ b/docker/nginx/leftypol.conf @@ -20,22 +20,7 @@ server { # Expire rules for static content # Media: images, icons, video, audio, HTC - location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { - expires 1M; - access_log off; - log_not_found off; - add_header Cache-Control "public"; - } - # CSS and Javascript - location ~* \.(?:css|js)$ { - expires 1y; - access_log off; - log_not_found off; - add_header Cache-Control "public"; - } - # Expire rules for static content - # Media: images, icons, video, audio, HTC - location ~* \.(?:jpg|jpeg|gif|png|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { + location ~* \.(?:jpg|jpeg|gif|png|webp|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { expires 1M; access_log off; log_not_found off; From 4ca2f5f3a310228b8065a8ecd9c178cf4819c15f Mon Sep 17 00:00:00 2001 From: Zankaria Date: Sat, 13 Apr 2024 12:53:12 +0200 Subject: [PATCH 4/4] docker: very aggressive CDN, media, css and js file caching on nginx site config --- docker/nginx/leftypol.conf | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/docker/nginx/leftypol.conf b/docker/nginx/leftypol.conf index 83f8b10a..b531e736 100644 --- a/docker/nginx/leftypol.conf +++ b/docker/nginx/leftypol.conf @@ -21,17 +21,16 @@ server { # Expire rules for static content # Media: images, icons, video, audio, HTC location ~* \.(?:jpg|jpeg|gif|png|webp|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ { - expires 1M; - access_log off; log_not_found off; - add_header Cache-Control "public"; + # Public cache, never changes until max-age expires, max-age of 1 month, can still be served while being + # revalidated or if the server is erroring for 1 day. + add_header Cache-Control "public, immutable, max-age=2592000, stale-while-revalidate=86400, stale-if-error=86400"; } # CSS and Javascript location ~* \.(?:css|js)$ { - expires 1y; - access_log off; log_not_found off; - add_header Cache-Control "public"; + # Public cache, max-age of 1 year, can still be served while being revalidated or if the server is erroring for 1 day. + add_header Cache-Control "public, max-age=31536000, stale-while-revalidate=86400, stale-if-error=86400"; } location ~* \.(html)$ {