]> git.openstreetmap.org Git - chef.git/commitdiff
Add nginx caching support + enable for imagery
authorGrant Slater <git@firefishy.com>
Sun, 29 May 2016 17:34:08 +0000 (18:34 +0100)
committerGrant Slater <git@firefishy.com>
Sun, 29 May 2016 17:34:41 +0000 (18:34 +0100)
cookbooks/imagery/templates/default/nginx_imagery_layer_fragment.conf.erb
cookbooks/nginx/attributes/default.rb
cookbooks/nginx/recipes/default.rb
cookbooks/nginx/templates/default/nginx.conf.erb
roles/imagery.rb

index 2e75717b0f18eb85dd35890d007e41c6bd2cd867..0f5d2b9a3358d807ebdef854b966c06655cdbf92 100644 (file)
@@ -5,6 +5,7 @@ location ~* "^/layer/<%= @layer %>/(\d+)/(\d+)/(\d+)\.(png|jpg|jpeg)$" {
   fastcgi_param QUERY_STRING "map=/srv/imagery/mapserver/layer-<%= @layer %>.map&mode=tile&layers=<%= @layer %>&tilemode=gmap&tile=$2+$3+$1";
   fastcgi_pass "unix:/var/run/mapserver-fastcgi/layer-<%= @layer %>.socket";
   fastcgi_buffers 8 64k;
+  fastcgi_cache "fastcgi_cache_zone"
   include fastcgi_params;
 
   gzip off;
index f28efd253f9934d544bb9721756fad5002b7745e..4e22759bf3b94bf2110d7915416c620a2cf68c24 100644 (file)
@@ -1 +1,11 @@
-# default[:nginx][:mpm] = "worker"
+# Tuning for nginx fastcgi cache zone
+default[:nginx][:cache][:fastcgi][:enable] = false
+default[:nginx][:cache][:fastcgi][:keys_zone] = "fastcgi_cache_zone:32m"
+default[:nginx][:cache][:fastcgi][:inactive] = "30d"
+default[:nginx][:cache][:fastcgi][:max_size] = "2048m"
+
+# Tuning for nginx proxy cache zone
+default[:nginx][:cache][:proxy][:enable] = false
+default[:nginx][:cache][:proxy][:keys_zone] = "proxy_cache_zone:32m"
+default[:nginx][:cache][:proxy][:inactive] = "30d"
+default[:nginx][:cache][:proxy][:max_size] = "2048m"
index 2c8b00a469baa65a41c83c92437de3b9faca591b..a5d06e1c0c3a0f646b8820048c2e6e2b0de53ef2 100644 (file)
@@ -28,6 +28,22 @@ template "/etc/nginx/nginx.conf" do
   mode 0644
 end
 
+if node['nginx']['cache']['fastcgi']['enable']
+  directory "/var/lib/nginx/fastcgi-cache" do
+    owner "nginx"
+    group "nginx"
+    mode 0755
+  end
+end
+
+if node['nginx']['cache']['proxy']['enable']
+  directory "/var/lib/nginx/proxy-cache" do
+    owner "nginx"
+    group "nginx"
+    mode 0755
+  end
+end
+
 service "nginx" do
   action [:enable]
   supports :status => true, :restart => true, :reload => true
index 13597d9fae79c2442613dfce7aabcaa99723942e..2099e8354641a96841ba88ff604c615c8a232748 100644 (file)
@@ -28,5 +28,12 @@ http {
 
     server_tokens off;
 
+    <% if node['nginx']['cache']['fastcgi']['enable'] -%>
+    fastcgi_cache_path /var/lib/nginx/fastcgi-cache levels=1:2 keys_zone=<%= node['nginx']['cache']['fastcgi']['keys_zone'] %> inactive=<%= node['nginx']['cache']['fastcgi']['inactive'] %> max_size=<%= node['nginx']['cache']['fastcgi']['max_size'] %>;
+    <% end -%>
+    <% if node['nginx']['cache']['proxy']['enable'] -%>
+    fastcgi_cache_path /var/lib/nginx/proxy-cache levels=1:2 keys_zone=<%= node['nginx']['cache']['proxy']['keys_zone'] %> inactive=<%= node['nginx']['cache']['proxy']['inactive'] %> max_size=<%= node['nginx']['cache']['proxy']['max_size'] %>;
+    <% end -%>
+
     include /etc/nginx/conf.d/*.conf;
 }
index 60bb1d930551b4cd580f099eb89f8da99a135c66..9106f932995bf7ff552411bfead1d4de74c3a482 100644 (file)
@@ -28,6 +28,13 @@ default_attributes(
         "kernel.sched_wakeup_granularity_ns" => 15000000
       }
     }
+  },
+  :nginx => {
+    :cache => {
+      :fastcgi => {
+        :enable => true
+      }
+    }
   }
 )