Deliver images in alternative formats

If the browser supports webp/avif images, nginx checks if any file with
the same name but the other formats extension is available.
This commit is contained in:
Moritz 'e1mo' Fromm 2023-04-13 13:47:05 +02:00 committed by Moritz
parent bf891ae2d9
commit cb4c29f1d7

View file

@ -23,14 +23,33 @@ in {
recommendedProxySettings = true; recommendedProxySettings = true;
recommendedTlsSettings = true; recommendedTlsSettings = true;
commonHttpConfig = ''
map $http_accept $webp_suffix {
default "";
"~*webp" ".webp";
}
map $http_accept $avif_suffix {
default "";
"~*avif" ".avif";
}
'';
virtualHosts.${baseDomain} = { virtualHosts.${baseDomain} = {
default = true; default = true;
enableACME = true; enableACME = true;
forceSSL = true; forceSSL = true;
serverAliases = [ "www.${baseDomain}" ]; serverAliases = [ "www.${baseDomain}" ];
# TODO: Change this to be deployed by some sort of CI + rsync so we don't need to always update the package version root = webroot;
locations."/".root = webroot; locations = {
locations."/.well-known/matrix/".alias = matrixWellKnownDir + "/"; "~* ^(/images/.+)\\.(png|jpe?g)$".extraConfig = ''
set $base $1;
add_header Vary Accept;
expires 7d;
add_header Cache-Control "must-revalidate, s-maxage=86400";
try_files $request_uri$avif_suffix $base$avif_suffix $request_uri$webp_suffix $base$webp_suffix $request_uri =404;
'';
"/.well-known/matrix/".alias = matrixWellKnownDir + "/";
};
}; };
}; };