1 # DO NOT EDIT - This file is being maintained by Chef
3 upstream tile_cache_backend {
4 server 127.0.0.1:8080 weight=1000 max_fails=32;
5 server 127.0.0.2:8080 weight=1000 max_fails=32;
7 # Add the tile_siblings caches to relieve pressure if local squid failing
8 # Balancer: round-robin
9 <% server_weight = 1000 -%>
10 <% Array(@node[:tilecache][:tile_siblings]).each do |cache_peer| -%>
11 <% @caches.each do |cache| -%>
12 <% if cache_peer == cache[:fqdn] -%>
13 <% if cache[:hostname] != node[:hostname] -%>
14 <% cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address| -%>
15 server <%= address %>:80 weight=<%= server_weight %> max_fails=32 backup; # Server <%= cache[:hostname] %>
16 <% server_weight -= server_weight.div(2) -%>
26 # Geo Map of tile caches
29 <% @caches.each do |cache| -%>
30 <% cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address| -%>
31 <%= address %> "cache"; # <%= cache[:hostname] %>
36 # Rates table based on current cookie value
37 # map $cookie__osm_totp_token $limit_rate_qos {
38 # include /etc/nginx/conf.d/tile_qos_rates.map;
41 # Set-Cookie table based on current cookie value
42 # map $cookie__osm_totp_token $cookie_qos_token_set {
43 # include /etc/nginx/conf.d/tile_qos_cookies.map;
46 map $http_user_agent $approved_scraper {
47 default 0; # Not approved
49 '~^Mozilla\/5\.0\ QGIS\/' 1; # QGIS
52 map $http_user_agent $denied_scraper {
53 default 0; # Not denied
54 '' 1; # No User-Agent Set
55 '~^Python\-urllib\/' 1; # Library Default
56 '~^python\-requests\/' 1; # Library Default
57 '~^node\-fetch\/' 1; # Library Default
58 '~^R$' 1; # Library Default
59 '~^Java\/' 1; # Library Default
60 '~^tiles$' 1; # Library Default
61 '~^okhttp\/' 1; # Library Default
62 '~^Microsoft-ATL-Native\/' 1; # Library Default
63 '/n software IPWorks HTTP/S Component - www.nsoftware.com' 1; #Library default
64 '~^Wget\/' 1; # Library Default
65 'C# TilesDownloader' 1; # Downloader
66 'MapDownloader' 1; # Downloader
67 '~^staticmaps' 1; # Downloader
68 'Android' 1; # Default or fake
69 'kc_android' 1; # Default or fake
70 'host' 1; # Default or fake
71 '~^maptestapp' 1; # Default or fake
72 'Other' 1; # Default or fake
73 'Mozilla/4.0' 1; # Fake
74 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)' 1; # Fake
75 '~^runtastic' 1; # App
76 '~^Where\ my\ children' 1; # App
77 'nossoonibusjp.android.crosswalk' 1; # App
78 'br.com.concisoti.potybus' 1; # App
79 'com.soft373.taptaxi' 1;
80 'com.kradac.ktxcore' 1;
81 'ru.crowdsystems.topcontrol.knd' 1;
83 'net.uztaxi.driver' 1;
84 'OSMDroid/2.1 (its; rutaxi 3.28.0)' 1;
85 'com.helleniccomms.mercedes.driver' 1;
86 'ru.taximaster.www' 1;
87 'com.arobs.trackgps' 1;
88 'com.helleniccomms.asteras.driver' 1;
89 # '~[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}' 1; # Fake UA
92 map $http_referer $denied_referer {
93 default 0; # Not denied
94 'http://www.openstreetmap.org/' 1; # Faked
95 'http://www.openstreetmap.org' 1; # Faked
96 'https://www.openstreetmap.org' 1; # Faked
97 'http://openstreetmap.org/' 1; # Faked
98 'http://openstreetmap.org' 1; # Faked
99 'https://openstreetmap.org' 1; # Faked
100 'http://www.osm.org/' 1; # Faked
101 'http://www.osm.org' 1; # Faked
102 'http://osm.org/' 1; # Faked
103 'http://osm.org' 1; # Faked
104 'http://google.com' 1; # Faked
105 'http://www.google.com' 1; # Faked
106 'http://google.com/' 1; # Faked
107 'http://www.google.com/' 1; # Faked
108 'https://google.com' 1; # Faked
109 'https://www.google.com' 1; # Faked
110 'https://google.com/' 1; # Faked
111 'https://www.google.com/' 1; # Faked
112 'http://www.microsoft.com/' 1; # Faked
113 '~^https?://pmap\.kuku\.lu/' 1; # Too much traffic
114 '~^https?://[^.]*\.pmap\.kuku\.lu/' 1; # Too much traffic
115 '~^https?://fastpokemap\.com/' 1; # Too much traffic
116 '~^https?://[^.]*\.fastpokemap\.com/' 1; # Too much traffic
117 '~^https?://pkget\.com/' 1; # Too much traffic
118 '~^https?://[^.]*\.pkget\.com/' 1; # Too much traffic
119 '~^https?://twpkinfo\.com/' 1; # Too much traffic
120 '~^https?://[^.]*\.twpkinfo\.com/' 1; # Too much traffic
121 '~^https?://9db\.jp/' 1; # Too much traffic
122 '~^https?://[^.]*\.9db\.jp/' 1; # Too much traffic
123 '~^https?://clustrmaps\.com/' 1; # Too much traffic
124 '~^https?://[^.]*\.clustrmaps\.com/' 1; # Too much traffic
125 '~^https?://geoportal360\.pl/' 1; # Too much traffic
126 '~^https?://skelbiu\.lt/' 1; # Too much traffic
127 '~^https?://[^.]*\.skelbiu\.lt/' 1; # Too much traffic
128 '~^https?://[^.]*\.wialon.com/' 1; # Too much traffic
131 map $http_referer $osm_referer {
133 '~^https:\/\/www\.openstreetmap\.org\/' 'osm'; # True
136 # Limit Cache-Control header to only approved User-Agents
137 map $tile_cache$osm_referer$http_user_agent $limit_http_cache_control {
138 default ''; # Unset Header
139 '~^clientosmMozilla\/5\.0\ \(X11' $http_cache_control; # Pass Header
140 '~^clientosmMozilla\/5\.0\ \(Windows' $http_cache_control; # Pass Header
141 '~^clientosmMozilla\/5\.0\ \(iPhone' $http_cache_control; # Pass Header
142 '~^clientosmMozilla\/5\.0\ \(Macintosh' $http_cache_control; # Pass Header
143 '~^clientosmMozilla\/5\.0\ \(Linux' $http_cache_control; # Pass Header
146 # Limit Pragma header to only approved User-Agents
147 map $tile_cache$osm_referer$http_user_agent $limit_http_pragma {
148 default ''; # Unset Header
149 '~^clientosmMozilla\/5\.0\ \(X11' $http_pragma; # Pass Header
150 '~^clientosmMozilla\/5\.0\ \(Windows' $http_pragma; # Pass Header
151 '~^clientosmMozilla\/5\.0\ \(iPhone' $http_pragma; # Pass Header
152 '~^clientosmMozilla\/5\.0\ \(Macintosh' $http_pragma; # Pass Header
153 '~^clientosmMozilla\/5\.0\ \(Linux' $http_pragma; # Pass Header
156 # Find Browser User-Agents which are not sending a referer.
157 # Browsers with no referer could be due to Browser extension or website Referrer-Policy
158 map $tile_cache$http_referer$scheme$http_user_agent $deny_missing_referer {
159 default 0; # Not denied
160 '~^clienthttpsMozilla\/5\.0\ \(X11' 1;
161 '~^clienthttpsMozilla\/5\.0\ \(Windows' 1;
162 '~^clienthttpsMozilla\/5\.0\ \(iPhone' 1;
163 '~^clienthttpsMozilla\/5\.0\ \(Macintosh' 1;
164 '~^clienthttpsMozilla\/5\.0\ \(Linux' 1;
169 listen 80 deferred backlog=16384 reuseport fastopen=2048 default_server;
170 listen 443 ssl deferred backlog=16384 reuseport fastopen=2048 http2 default_server;
172 listen [::]:80 deferred backlog=16384 reuseport fastopen=2048 default_server;
173 listen [::]:443 ssl deferred backlog=16384 reuseport fastopen=2048 http2 default_server;
174 server_name localhost;
177 proxy_busy_buffers_size 64k;
179 ssl_certificate /etc/ssl/certs/tile.openstreetmap.org.pem;
180 ssl_certificate_key /etc/ssl/private/tile.openstreetmap.org.key;
182 # Requests sent within early data are subject to replay attacks.
183 # See: http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_early_data
186 # Immediately 404 layers we do not support
187 <% for i in 20..99 do %>
188 location /<%= i %>/ {
193 # Immediately 404 silly tile requests
194 location = /0/0/-1.png {
197 location = /1/0/-1.png {
200 location = /1/-1/0.png {
203 location = /1/-1/1.png {
206 location = /1/-1/-1.png {
209 location = /1/-1/2.png {
212 location = /1/1/-1.png {
215 location = /1/2/-1.png {
218 location = /2/0/-1.png {
221 location = /2/-1/0.png {
224 location = /2/-1/1.png {
227 location = /2/1/-1.png {
230 location = /2/-1/2.png {
233 location = /2/-1/3.png {
237 <% for i in 0..16 do %>
239 # Default Fallback Location Handler (lowest)
242 # Dedicated zoom handler for caching
243 location /<%= i %>/ {
245 # Only allow GET / HEAD / OPTIONS (CORS) requests
246 limit_except GET HEAD OPTIONS {
250 proxy_pass http://tile_cache_backend;
251 proxy_set_header X-Forwarded-For $remote_addr;
252 proxy_http_version 1.1;
253 proxy_set_header Connection '';
255 proxy_connect_timeout 20s;
257 proxy_next_upstream_tries 2;
259 # Replace host header.
260 proxy_set_header Host 'tile.openstreetmap.org';
261 # Do not pass cookies to backends.
262 proxy_set_header Cookie '';
263 # Do not pass Accept-Encoding to backends.
264 proxy_set_header Accept-Encoding '';
265 # Do not pass Accept to backends.
266 proxy_set_header Accept '';
267 # Do not pass Accept-Language to backends as unused.
268 proxy_set_header Accept-Language '';
269 proxy_set_header Accept-Charset '';
270 # Do not send origin, we allow all.
271 proxy_set_header origin '';
272 # Do not pass invalid headers to backend.
273 proxy_set_header X-Forwarded-Host '';
274 proxy_set_header X-Host '';
275 proxy_set_header Authorization '';
276 proxy_set_header Proxy-Authorization '';
278 # Drop partial requests
279 proxy_set_header range '';
281 # Do not allow setting cookies from backends due to caching.
282 proxy_ignore_headers Set-Cookie;
283 proxy_hide_header Set-Cookie;
287 proxy_cache "proxy_cache_zone";
289 proxy_cache_valid 200 2d;
290 proxy_cache_valid 404 15m;
291 # Serve stale cache on errors or if updating
292 proxy_cache_use_stale error timeout updating http_404 http_500 http_503 http_504;
293 # If in cache as stale, serve stale and update in background
294 proxy_cache_background_update on;
295 # Workaround nginx async bug which causes stale cache replies to wait for the async backend cache update reply (seen in v1.16.0)
296 keepalive_requests 0;
297 # Enable revalidation using If-Modified-Since and If-None-Match for stale items
298 proxy_cache_revalidate on;
299 proxy_cache_min_uses 4;
301 add_header x-cache-status "$upstream_cache_status - <%= node[:hostname] %>";
303 # Severely rate limit Browser UAs which are not sending a referer.
304 # With no referer we do not know who is using tiles
305 if ($deny_missing_referer) {
306 set $limit_rate 1024;
307 add_header x-cache-ratelimit "missing-referer";
311 # Set a QoS cookie if none presented (uses nginx Map)
312 # add_header Set-Cookie $cookie_qos_token_set;
313 <% if node[:ssl][:strict_transport_security] -%>
314 # Ensure Strict-Transport-Security header is removed from proxied server responses
315 proxy_hide_header Strict-Transport-Security;
318 add_header Strict-Transport-Security "<%= node[:ssl][:strict_transport_security] %>" always;
321 # QoS Traffic Rate see $limit_rate on http://nginx.org/en/docs/http/ngx_http_core_module.html
322 # set $limit_rate $limit_rate_qos;
324 # Allow Higher Traffic Rate from Approved User-Agents which do not support cookies (uses nginx Map)
325 # if ($approved_scraper) {
326 # set $limit_rate 65536;
329 if ($denied_scraper) {
333 if ($denied_referer) {
338 # Strip any ?query parameters from urls
341 # Allow cache purging headers only from select User-Agents (uses nginx Map)
342 proxy_set_header Cache-Control $limit_http_cache_control;
343 proxy_set_header Pragma $limit_http_pragma;