From b2a1a4821c20e61162c43fe5dfb8ab695fa5519b Mon Sep 17 00:00:00 2001
From: paspo <paolo@asperti.com>
Date: Mon, 21 Oct 2024 21:24:00 +0000
Subject: [PATCH] fix content-type e rewrite ICS (#301)

fixes #300

Reviewed-on: https://git.libreschool.org/BgLUG/bglug.it/pulls/301
Co-authored-by: paspo <paolo@asperti.com>
Co-committed-by: paspo <paolo@asperti.com>
---
 docker/rootfs/etc/nginx/http.d/default.conf | 28 +++++++--------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/docker/rootfs/etc/nginx/http.d/default.conf b/docker/rootfs/etc/nginx/http.d/default.conf
index ef5c44d..b57b670 100644
--- a/docker/rootfs/etc/nginx/http.d/default.conf
+++ b/docker/rootfs/etc/nginx/http.d/default.conf
@@ -6,12 +6,14 @@ server {
     sendfile        off;
     root            /wwwroot;
     index           index.html;
+    error_page      404 /it/404.html;
+    add_header      X-Frame-Options "SAMEORIGIN";
+    add_header      X-Content-Type-Options "nosniff";
+    add_header      Strict-Transport-Security "max-age=15768000; includeSubDomains; preload";
+    add_header      Content-Security-Policy "default-src 'self'; img-src https://*; child-src 'none';";
     
-    location ~ .* {
-        add_header X-Frame-Options "SAMEORIGIN";
-        add_header X-Content-Type-Options "nosniff";
-        add_header Strict-Transport-Security "max-age=15768000; includeSubDomains; preload";
-        add_header Content-Security-Policy "default-src 'self'; img-src https://*; child-src 'none';";
+    types {
+        text/calendar  ics;
     }
 
     location ~ ^/feed {
@@ -19,30 +21,18 @@ server {
         rewrite ^/feed/.*$ /it/index.xml last;
     }
 
-    location ~ /events/elenco/ {
-        default_type "text/calendar";
-        try_files $uri /it/index.ics;
-    }
-
-    location ~ \.ics$ {
+    location ~ ^/events/elenco/ {
         default_type "text/calendar";
+        rewrite ^/events/elenco/.*$ /it/index.ics last;
     }
 
     location ~ ^/wp\-content/uploads/2008/02/Statuto\.pdf$ {
         return 301 https://bglug.it/it/chi-siamo/Statuto.pdf;
     }
 
-    location ~ ^/it/.* {
-        error_page 404 /it/404.html;
-    }
-
     location ~ ^/en/.* {
         error_page 404 /en/404.html;
     }
-
-    location ~ .* {
-        error_page 404 /it/404.html;
-    }
 }
 
 gzip on;