forked from leftypol/leftypol
Merge pull request 'Redirect for banners' (#116) from banner-redirect into config
Reviewed-on: leftypol/leftypol#116
This commit is contained in:
commit
b942250a16
18
banners.php
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');
|
||||
|
|
|
@ -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)$ {
|
||||
|
|
|
@ -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…
Reference in New Issue
Block a user