forked from leftypol/leftypol
Merge pull request 'Redirect for banners' (#116) from banner-redirect into config
Reviewed-on: https://git.leftypol.org/leftypol/leftypol/pulls/116
This commit is contained in:
commit
b942250a16
3 changed files with 12 additions and 36 deletions
18
banners.php
18
banners.php
|
@ -1,16 +1,8 @@
|
||||||
<?php
|
<?php
|
||||||
function getBannerSrc(){
|
|
||||||
$files = scandir(__dir__.'/banners/');
|
|
||||||
$files = array_diff($files, array('.', '..'));
|
|
||||||
return $files[array_rand($files)];
|
|
||||||
}
|
|
||||||
|
|
||||||
$filename = getBannerSrc();
|
$files = scandir(__dir__ . '/banners/', SCANDIR_SORT_NONE);
|
||||||
$filename = "banners/" . $filename;
|
$files = array_diff($files, ['.', '..']);
|
||||||
$fp = fopen($filename, 'rb');
|
|
||||||
|
|
||||||
header("Content-Type: image/png");
|
$filename = $files[array_rand($files)];
|
||||||
header("Content-Length: " . filesize($filename));
|
header("Location: /banners/$filename", true, 307);
|
||||||
|
header('Cache-Control: no-cache');
|
||||||
fpassthru($fp);
|
|
||||||
?>
|
|
||||||
|
|
|
@ -20,33 +20,17 @@ server {
|
||||||
|
|
||||||
# Expire rules for static content
|
# Expire rules for static content
|
||||||
# Media: images, icons, video, audio, HTC
|
# 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;
|
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
|
# CSS and Javascript
|
||||||
location ~* \.(?:css|js)$ {
|
location ~* \.(?:css|js)$ {
|
||||||
expires 1y;
|
|
||||||
access_log off;
|
|
||||||
log_not_found 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";
|
||||||
# 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";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
location ~* \.(html)$ {
|
location ~* \.(html)$ {
|
||||||
|
|
|
@ -25,7 +25,6 @@ fi
|
||||||
|
|
||||||
# Link the entrypoints from the exposed directory.
|
# Link the entrypoints from the exposed directory.
|
||||||
ln -nfs \
|
ln -nfs \
|
||||||
/code/banners/ \
|
|
||||||
/code/tools/ \
|
/code/tools/ \
|
||||||
/code/walls/ \
|
/code/walls/ \
|
||||||
/code/*.php \
|
/code/*.php \
|
||||||
|
@ -36,6 +35,7 @@ ln -nfs \
|
||||||
# Static files accessible from the webserver must be copied.
|
# Static files accessible from the webserver must be copied.
|
||||||
cp -ur /code/static /var/www/
|
cp -ur /code/static /var/www/
|
||||||
cp -ur /code/stylesheets /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.
|
# Ensure correct permissions are set, since this might be bind mount.
|
||||||
chown www-data /var/www
|
chown www-data /var/www
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue