Browse Source

Merge pull request 'Redirect for banners' (#116) from banner-redirect into config

Reviewed-on: #116
fix-hud-dash
Zankaria 3 weeks ago
parent
commit
b942250a16
  1. 18
      banners.php
  2. 28
      docker/nginx/leftypol.conf
  3. 2
      docker/php/bootstrap.sh

18
banners.php

@ -1,16 +1,8 @@
<?php
function getBannerSrc(){
$files = scandir(__dir__.'/banners/');
$files = array_diff($files, array('.', '..'));
return $files[array_rand($files)];
}
$filename = getBannerSrc();
$filename = "banners/" . $filename;
$fp = fopen($filename, 'rb');
$files = scandir(__dir__ . '/banners/', SCANDIR_SORT_NONE);
$files = array_diff($files, ['.', '..']);
header("Content-Type: image/png");
header("Content-Length: " . filesize($filename));
fpassthru($fp);
?>
$filename = $files[array_rand($files)];
header("Location: /banners/$filename", true, 307);
header('Cache-Control: no-cache');

28
docker/nginx/leftypol.conf

@ -20,33 +20,17 @@ 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;
location ~* \.(?:jpg|jpeg|gif|png|webp|ico|cur|gz|svg|svgz|mp4|ogg|ogv|webm|htc)$ {
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";
}
# 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";
# 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)$ {

2
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

Loading…
Cancel
Save