From dc225a57dde2aef7c9068a2d7d577d5dd918fa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eirik=20=C3=98verby?= Date: Mon, 20 Jan 2025 19:17:03 +0100 Subject: [PATCH] www/nginx: Add basic support for forced caching (#4481) --- .../mvc/app/controllers/OPNsense/Nginx/forms/location.xml | 7 +++++++ .../src/opnsense/mvc/app/models/OPNsense/Nginx/Nginx.xml | 3 +++ .../service/templates/OPNsense/Nginx/location.conf | 3 +++ 3 files changed, 13 insertions(+) diff --git a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/forms/location.xml b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/forms/location.xml index c5ad99827..d6ee67abb 100644 --- a/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/forms/location.xml +++ b/www/nginx/src/opnsense/mvc/app/controllers/OPNsense/Nginx/forms/location.xml @@ -96,6 +96,13 @@ true Enter how often the resource must be hit before adding it to the cache. + + location.cache_valid + + text + true + Force caching of 200, 301 and 302 responses according to the request methods enabled for caching. Given in minutes; leave empty to rely on request/response headers from client and upstream. + location.cache_background_update diff --git a/www/nginx/src/opnsense/mvc/app/models/OPNsense/Nginx/Nginx.xml b/www/nginx/src/opnsense/mvc/app/models/OPNsense/Nginx/Nginx.xml index 7c0e82167..22f15d3ff 100644 --- a/www/nginx/src/opnsense/mvc/app/models/OPNsense/Nginx/Nginx.xml +++ b/www/nginx/src/opnsense/mvc/app/models/OPNsense/Nginx/Nginx.xml @@ -349,6 +349,9 @@ Y 1 + + N + Y 0 diff --git a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/location.conf b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/location.conf index 80f2d3b02..9f9b57603 100644 --- a/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/location.conf +++ b/www/nginx/src/opnsense/service/templates/OPNsense/Nginx/location.conf @@ -142,6 +142,9 @@ location {{ location.matchtype }} {{ location.urlpattern }} { proxy_cache {{ location.cache_path.replace('-', '') }}; {% if location.cache_use_stale is defined and location.cache_use_stale != '' %} proxy_cache_use_stale {{ location.cache_use_stale.replace(',', ' ') }}; +{% endif %} +{% if location.cache_valid is defined and location.cache_valid != '' %} + proxy_cache_valid {{ location.cache_valid }}m; {% endif %} proxy_cache_min_uses {{ location.cache_min_uses|default('1') }}; proxy_cache_background_update {% if location.cache_background_update is defined and location.cache_background_update == '1' %}on{% else %}off{% endif %};