From 1359746781ceb78e1e1bbc0a2c333631f402e0ab Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Thu, 21 Nov 2024 01:42:28 +0100 Subject: [PATCH 1/2] feat: nginx: cache responses from app/download.php results This configuration change prevents the browser from systematically downloading thumbnails of uploaded files. Because "uploads" URLs are always pointing to the same exact file, we can cache the response. --- src/nginx/common.conf | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/nginx/common.conf b/src/nginx/common.conf index 81dacb5..e1bdf90 100644 --- a/src/nginx/common.conf +++ b/src/nginx/common.conf @@ -78,6 +78,18 @@ location = /nginx-status { # deny access to hidden files/folders location ~ /\. { access_log off; log_not_found off; deny all; } +# for user uploaded files, use a long cache value, as uploads are not modified anyway: an URL points always to the same exact file +location ^~ /app/download.php { + more_set_headers Cache-Control "public, max-age=31536000"; + include /etc/nginx/fastcgi.conf; + fastcgi_index index.php; + log_not_found off; + + if (-f $request_filename) { + fastcgi_pass unix:/run/php-fpm.sock; + } +} + # assets configuration location ~* \.(js|css|png|jpg|jpeg|gif|ico|map|ttf|txt|woff|woff2|svg|webmanifest)$ { access_log off; From bd5e61187436c3411bb83c35aa8bed14936db397 Mon Sep 17 00:00:00 2001 From: Nicolas CARPi Date: Thu, 21 Nov 2024 01:46:12 +0100 Subject: [PATCH 2/2] use correct syntax for more_set_headers --- src/nginx/common.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nginx/common.conf b/src/nginx/common.conf index e1bdf90..8bb0e82 100644 --- a/src/nginx/common.conf +++ b/src/nginx/common.conf @@ -80,7 +80,7 @@ location ~ /\. { access_log off; log_not_found off; deny all; } # for user uploaded files, use a long cache value, as uploads are not modified anyway: an URL points always to the same exact file location ^~ /app/download.php { - more_set_headers Cache-Control "public, max-age=31536000"; + more_set_headers "Cache-Control: public, max-age=31536000"; include /etc/nginx/fastcgi.conf; fastcgi_index index.php; log_not_found off;