Merge pull request 'Cache successful Blossom responses' (#666) from feature/blossom_cache into master

Reviewed-on: #666
Reviewed-by: Greg <greg@kosmos.org>
This commit was merged in pull request #666.
This commit is contained in:
2026-08-16 18:52:30 +00:00
5 changed files with 31 additions and 3 deletions
+1 -1
Submodule nodes updated: 5fd2e23a01...90c15e40f8
@@ -1 +1,3 @@
# No attributes here, use the blossom cookbook's attributes
node.default['blossom']['nginx_cache_max_size'] = '1g'
@@ -23,6 +23,7 @@ openresty_site domain do
upstream_host: blossom_node['knife_zero']['host'],
upstream_port: node['blossom']['port'],
max_size_mb: node['blossom']['max_size'] / 1024 / 1024,
cache_max_size: node['blossom']['nginx_cache_max_size'],
ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem",
ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem"
end
@@ -2,12 +2,16 @@ upstream _blossom {
server <%= @upstream_host %>:<%= @upstream_port %>;
}
proxy_cache_path <%= node['openresty']['cache_dir'] %>/blossom
keys_zone=blossom_cache:10m
max_size=<%= @cache_max_size %> inactive=100y use_temp_path=off;
server {
server_name <%= @domain %>;
listen <%= "#{node['openresty']['listen_ip']}:" if node['openresty']['listen_ip'] %>443 ssl http2;
listen <%= "[#{node['openresty']['listen_ipv6']}]" %>:443 ssl http2;
access_log "/var/log/nginx/<%= @domain %>.access.log";
access_log "/var/log/nginx/<%= @domain %>.access.log" json;
error_log "/var/log/nginx/<%= @domain %>.error.log";
client_max_body_size <%= @max_size_mb %>M;
@@ -15,6 +19,27 @@ server {
ssl_certificate <%= @ssl_cert %>;
ssl_certificate_key <%= @ssl_key %>;
location ~ "^/(?<sha256>[a-f0-9]{64})(\.[a-zA-Z0-9]+)?$" {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_pass http://_blossom;
proxy_http_version 1.1;
proxy_cache blossom_cache;
proxy_cache_key $sha256;
proxy_cache_valid 200 1y;
proxy_cache_lock on;
proxy_cache_use_stale error timeout updating;
log_by_lua_block {
if ngx.var.request_method == "DELETE" and ngx.status >= 200 and ngx.status < 300 then
os.remove("<%= node['openresty']['cache_dir'] %>/blossom/" .. ngx.md5(ngx.var.sha256))
end
}
}
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
@@ -3,7 +3,7 @@
# Recipe:: default
#
node.normal['openresty']['log_formats']['json'] = '{"ip":"$remote_addr","time":"$time_local","host":"$host","method":"$request_method","uri":"$uri","status":$status,"size":$body_bytes_sent,"referer":"$http_referer","upstream_addr":"$upstream_addr","upstream_response_time":"$upstream_response_time","ua":"$http_user_agent"}'
node.normal['openresty']['log_formats']['json'] = '{"ip":"$remote_addr","time":"$time_local","host":"$host","method":"$request_method","uri":"$uri","status":$status,"size":$body_bytes_sent,"referer":"$http_referer","upstream_addr":"$upstream_addr","upstream_response_time":"$upstream_response_time","upstream_cache_status":"$upstream_cache_status","ua":"$http_user_agent"}'
# Install openresty from official packages
include_recipe 'openresty::apt_package'