2 # DO NOT EDIT - This file is being maintained by Chef
 
   3 location ~* "^/layer/<%= @layer %>/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" {
 
   6   rewrite ^/layer/<%= @layer %>/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp) /mosaicjson/tiles/WebMercatorQuad/$1/$2/$3@1x.$4?url=<%= URI.encode_www_form_component(@source) %>&pixel_selection=first break;
 
   7   proxy_pass http://<%= @site %>_tiler_backend;
 
   8   proxy_set_header Host $host;
 
   9   proxy_set_header Referer $http_referer;
 
  10   proxy_set_header X-Forwarded-For $remote_addr;
 
  11   proxy_set_header X-Forwarded-Proto https;
 
  12   proxy_set_header X-Forwarded-SSL on;
 
  13   proxy_http_version 1.1;
 
  14   proxy_set_header Connection "";
 
  15   proxy_set_header Cache-Control "";
 
  16   proxy_set_header Pragma "";
 
  18   proxy_cache_key "<%= @layer %><%= @revision %> $request_method $1 $2 $3 $4";
 
  19   proxy_cache proxy_cache_zone;
 
  20   proxy_cache_valid 200 204 180d;
 
  21   proxy_cache_use_stale error timeout updating http_502 http_503 http_504;
 
  22   proxy_cache_background_update on;
 
  23   proxy_next_upstream error timeout invalid_header http_500 http_503;
 
  24   proxy_next_upstream_timeout 30s;
 
  25   proxy_next_upstream_tries 3;
 
  26   proxy_intercept_errors on;
 
  27   proxy_ignore_headers "Cache-Control";
 
  28   proxy_ignore_headers "Expires";
 
  29   proxy_hide_header "Cache-Control";
 
  30   proxy_hide_header "Expires";
 
  31   proxy_hide_header "Access-Control-Allow-Origin";
 
  33   # Override QUERY_STRING to force mapserver query parameters
 
  34   fastcgi_param QUERY_STRING "map=/srv/imagery/mapserver/layer-<%= @layer %>.map&mode=tile&layers=<%= @layer %>&tilemode=gmap&tile=$2+$3+$1";
 
  35   fastcgi_pass "<%= @site %>_fastcgi";
 
  36   include fastcgi_params;
 
  37   fastcgi_param REQUEST_METHOD "GET";
 
  38   fastcgi_param HTTP_PROXY "";
 
  39   fastcgi_read_timeout 60s;
 
  42   fastcgi_cache "fastcgi_cache_zone";
 
  43   fastcgi_cache_key "<%= @layer %><%= @revision %> $request_method $1 $2 $3";
 
  45   # Free connection to socket for other requests
 
  46   fastcgi_keep_conn off;
 
  48   fastcgi_cache_valid 200 21d;
 
  50   # Serve stale cache on errors or if updating
 
  51   fastcgi_cache_use_stale error timeout updating http_500 http_503;
 
  52   # If in cache as stale, serve stale and update in background
 
  53   fastcgi_cache_background_update on;
 
  54   # Enable revalidation using If-Modified-Since and If-None-Match for stale items
 
  55   fastcgi_cache_revalidate on;
 
  59   fastcgi_catch_stderr "Image handling error";
 
  61   fastcgi_next_upstream error timeout invalid_header http_500 http_503;
 
  62   fastcgi_next_upstream_tries 8;
 
  68   # Add HTTP Cache-Control + Expires Headers
 
  70   add_header Cache-Control "stale-while-revalidate=2678400, stale-if-error=2678400";
 
  71   add_header x-cache-status $upstream_cache_status;
 
  74   add_header 'Access-Control-Allow-Origin' '*' always;
 
  78 rewrite "^/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" "/layer/<%= @layer %>/$1/$2/$3.$4" last;
 
  80 <% @url_aliases.each do |url| -%>
 
  81 rewrite "^<%= url %>/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" "/layer/<%= @layer %>/$1/$2/$3.$4" last;