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 @tile_backend;
13 # Return transparent PNG for HTTP 204 (no content) responses from backend
14 error_page 204 =200 /transparent.png;
18 add_header Cache-Control "stale-while-revalidate=2678400, stale-if-error=2678400";
19 add_header x-cache-status $upstream_cache_status;
20 add_header 'Access-Control-Allow-Origin' '*' always;
23 location @tile_backend {
27 set $upstream_uri /mosaicjson/tiles/WebMercatorQuad/$z/$x/$y@1x.$ext?url=<%= URI.encode_www_form_component(@source) %>&pixel_selection=first;
29 proxy_pass http://<%= @site %>_tiler_backend$upstream_uri;
30 proxy_set_header Host $host;
31 proxy_set_header Referer $http_referer;
32 proxy_set_header X-Forwarded-For $remote_addr;
33 proxy_set_header X-Forwarded-Proto https;
34 proxy_set_header X-Forwarded-SSL on;
35 proxy_http_version 1.1;
36 proxy_set_header Connection "";
37 proxy_set_header Cache-Control "";
38 proxy_set_header Pragma "";
41 proxy_cache_key "<%= @layer %><%= @revision %> $request_method $z $x $y $ext";
42 proxy_cache proxy_cache_zone;
43 proxy_cache_valid 200 204 180d;
44 proxy_cache_use_stale error timeout updating http_502 http_503 http_504;
45 proxy_cache_background_update on;
47 proxy_next_upstream error timeout invalid_header http_500 http_503;
48 proxy_next_upstream_timeout 30s;
49 proxy_next_upstream_tries 3;
51 proxy_intercept_errors on;
52 proxy_ignore_headers "Cache-Control";
53 proxy_ignore_headers "Expires";
54 proxy_hide_header "Cache-Control";
55 proxy_hide_header "Expires";
56 proxy_hide_header "Access-Control-Allow-Origin";
57 proxy_hide_header "Content-BBOX";
58 proxy_hide_header "Content-CRS";
60 # Override QUERY_STRING to force mapserver query parameters
61 fastcgi_param QUERY_STRING "map=/srv/imagery/mapserver/layer-<%= @layer %>.map&mode=tile&layers=<%= @layer %>&tilemode=gmap&tile=$x+$y+$z";
62 fastcgi_pass "<%= @site %>_fastcgi";
63 include fastcgi_params;
64 fastcgi_param REQUEST_METHOD "GET";
65 fastcgi_param HTTP_PROXY "";
66 fastcgi_read_timeout 60s;
69 fastcgi_cache "fastcgi_cache_zone";
70 fastcgi_cache_key "<%= @layer %><%= @revision %> $request_method $z $x $y";
72 # Free connection to socket for other requests
73 fastcgi_keep_conn off;
75 fastcgi_cache_valid 200 21d;
77 # Serve stale cache on errors or if updating
78 fastcgi_cache_use_stale error timeout updating http_500 http_503;
79 # If in cache as stale, serve stale and update in background
80 fastcgi_cache_background_update on;
81 # Enable revalidation using If-Modified-Since and If-None-Match for stale items
82 fastcgi_cache_revalidate on;
86 fastcgi_catch_stderr "Image handling error";
88 fastcgi_next_upstream error timeout invalid_header http_500 http_503;
89 fastcgi_next_upstream_tries 8;
93 add_header Cache-Control "stale-while-revalidate=2678400, stale-if-error=2678400";
94 add_header x-cache-status $upstream_cache_status;
95 add_header 'Access-Control-Allow-Origin' '*' always;
99 rewrite "^/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" "/layer/<%= @layer %>/$1/$2/$3.$4" last;
101 <% @url_aliases.each do |url| -%>
102 rewrite "^<%= url %>/(\d+)/(\d+)/(\d+)\.(jpg|jpeg|png|webp)$" "/layer/<%= @layer %>/$1/$2/$3.$4" last;