From 803b66060630cad699f04744ce9017ca7a388e58 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Mon, 11 Sep 2023 17:39:20 +0200 Subject: [PATCH 1/2] implementing media caching --- conf/nginx.conf | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/conf/nginx.conf b/conf/nginx.conf index 1a4cd60..c1a87f0 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -13,3 +13,31 @@ location __PATH__/ { # Include SSOWAT user panel. include conf.d/yunohost_panel.conf.inc; } + + +# media caching stuff +# https://docs.gotosocial.org/en/latest/advanced/caching/assets-media/#nginx + +location /assets/ { + alias web-asset-base-dir/; + autoindex off; + expires 5m; + add_header Cache-Control "public"; +} + +location @fileserver { + proxy_pass http://localhost:__PORT__; + proxy_set_header Host $host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; +} + +location /fileserver/ { + alias storage-local-base-path/; + autoindex off; + expires 1w; + add_header Cache-Control "private, immutable"; + try_files $uri @fileserver; +} \ No newline at end of file From d436324ae33ccb8e5463cc47ada69a1ea7d80f52 Mon Sep 17 00:00:00 2001 From: OniriCorpe Date: Mon, 11 Sep 2023 19:18:27 +0200 Subject: [PATCH 2/2] finalizing nginx media caching conf & various fixes --- conf/nginx.conf | 66 +++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index c1a87f0..7bf49a7 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,43 +1,45 @@ location __PATH__/ { proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $host; - - proxy_pass http://localhost:__PORT__; - - client_max_body_size __CLIENT_MAX_BODY_SIZE__; - - # Include SSOWAT user panel. - include conf.d/yunohost_panel.conf.inc; -} - - -# media caching stuff -# https://docs.gotosocial.org/en/latest/advanced/caching/assets-media/#nginx - -location /assets/ { - alias web-asset-base-dir/; - autoindex off; - expires 5m; - add_header Cache-Control "public"; -} - -location @fileserver { - proxy_pass http://localhost:__PORT__; proxy_set_header Host $host; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + + proxy_pass http://127.0.0.1:__PORT__; + + client_max_body_size __CLIENT_MAX_BODY_SIZE__; + + # Include SSOWAT user panel. + include conf.d/yunohost_panel.conf.inc; + + + # media caching stuff + # https://docs.gotosocial.org/en/latest/advanced/caching/assets-media/#nginx + location /assets/ { + alias __FINAL_PATH__/web/assets/; + autoindex off; + expires 5m; + add_header Cache-Control "public"; + } + + location /fileserver/ { + alias __DATADIR__; + autoindex off; + expires 1w; + add_header Cache-Control "private, immutable"; + try_files $uri @fileserver; + } + } -location /fileserver/ { - alias storage-local-base-path/; - autoindex off; - expires 1w; - add_header Cache-Control "private, immutable"; - try_files $uri @fileserver; +location @fileserver { + proxy_pass http://127.0.0.1:__PORT__; + proxy_set_header Host $host; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header X-Forwarded-Proto $scheme; } \ No newline at end of file