2 # DO NOT EDIT - This file is being maintained by Chef
 
   3 location ~* "^/layer/<%= @layer %>/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" {
 
   4   # keep captures in variables for use in the named location
 
  10   # Serve local file if present; otherwise jump to proxy
 
  11   try_files /layer/<%= @layer %>/$z/$x/$y.jpg /layer/<%= @layer %>/$z/$x/$y.jpeg /layer/<%= @layer %>/$z/$x/$y.png /layer/<%= @layer %>/$z/$x/$y.webp @<%= @site %>_<%= @layer %>_backend;
 
  15   add_header Cache-Control "stale-while-revalidate=2678400, stale-if-error=2678400";
 
  16   add_header x-cache-status $upstream_cache_status;
 
  17   add_header 'Access-Control-Allow-Origin' '*' always;
 
  20 location @<%= @site %>_<%= @layer %>_backend {
 
  24   set $upstream_uri /mosaicjson/tiles/WebMercatorQuad/$z/$x/$y@1x.$ext?url=<%= URI.encode_www_form_component(@source) %>&pixel_selection=first;
 
  26   proxy_pass http://<%= @site %>_tiler_backend$upstream_uri;
 
  27   proxy_set_header Host $host;
 
  28   proxy_set_header Referer $http_referer;
 
  29   proxy_set_header X-Forwarded-For $remote_addr;
 
  30   proxy_set_header X-Forwarded-Proto https;
 
  31   proxy_set_header X-Forwarded-SSL on;
 
  32   proxy_http_version 1.1;
 
  33   proxy_set_header Connection "";
 
  34   proxy_set_header Cache-Control "";
 
  35   proxy_set_header Pragma "";
 
  38   proxy_cache_key "<%= @layer %><%= @revision %> $request_method $z $x $y $ext";
 
  39   proxy_cache proxy_cache_zone;
 
  40   proxy_cache_valid 200 204 180d;
 
  41   proxy_cache_use_stale error timeout updating http_502 http_503 http_504;
 
  42   proxy_cache_background_update on;
 
  44   proxy_next_upstream error timeout invalid_header http_500 http_503;
 
  45   proxy_next_upstream_timeout 30s;
 
  46   proxy_next_upstream_tries 3;
 
  48   proxy_intercept_errors on;
 
  49   proxy_ignore_headers "Cache-Control";
 
  50   proxy_ignore_headers "Expires";
 
  51   proxy_hide_header "Cache-Control";
 
  52   proxy_hide_header "Expires";
 
  53   proxy_hide_header "Access-Control-Allow-Origin";
 
  54   proxy_hide_header "Content-BBOX";
 
  55   proxy_hide_header "Content-CRS";
 
  57   # Override QUERY_STRING to force mapserver query parameters
 
  58   fastcgi_param QUERY_STRING "map=/srv/imagery/mapserver/layer-<%= @layer %>.map&mode=tile&layers=<%= @layer %>&tilemode=gmap&tile=$x+$y+$z";
 
  59   fastcgi_pass "<%= @site %>_fastcgi";
 
  60   include fastcgi_params;
 
  61   fastcgi_param REQUEST_METHOD "GET";
 
  62   fastcgi_param HTTP_PROXY "";
 
  63   fastcgi_read_timeout 60s;
 
  66   fastcgi_cache "fastcgi_cache_zone";
 
  67   fastcgi_cache_key "<%= @layer %><%= @revision %> $request_method $z $x $y";
 
  69   # Free connection to socket for other requests
 
  70   fastcgi_keep_conn off;
 
  72   fastcgi_cache_valid 200 21d;
 
  74   # Serve stale cache on errors or if updating
 
  75   fastcgi_cache_use_stale error timeout updating http_500 http_503;
 
  76   # If in cache as stale, serve stale and update in background
 
  77   fastcgi_cache_background_update on;
 
  78   # Enable revalidation using If-Modified-Since and If-None-Match for stale items
 
  79   fastcgi_cache_revalidate on;
 
  83   fastcgi_catch_stderr "Image handling error";
 
  85   fastcgi_next_upstream error timeout invalid_header http_500 http_503;
 
  86   fastcgi_next_upstream_tries 8;
 
  90   add_header Cache-Control "stale-while-revalidate=2678400, stale-if-error=2678400";
 
  91   add_header x-cache-status $upstream_cache_status;
 
  92   add_header 'Access-Control-Allow-Origin' '*' always;
 
  96 rewrite "^/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" "/layer/<%= @layer %>/$1/$2/$3.$4" last;
 
  98 <% @url_aliases.each do |url| -%>
 
  99 rewrite "^<%= url %>/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" "/layer/<%= @layer %>/$1/$2/$3.$4" last;