1 # DO NOT EDIT - This file is being maintained by Chef
3 upstream tile_cache_backend {
5 <% @caches.each do |cache| -%>
6 <% if cache[:hostname] != node[:hostname] -%>
7 #Server <%= cache[:hostname] %>
8 <% cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address| -%>
9 server <%= address %> backup;
17 # Rates table based on current cookie value
18 map $cookie_qos_token $limit_rate_qos {
19 include /etc/nginx/conf.d/tile_qos_rates.map;
22 # Set-Cookie table based on current cookie value
23 map $cookie_qos_token $cookie_qos_token_set {
24 include /etc/nginx/conf.d/tile_qos_cookies.map;
27 map $http_user_agent $approved_scraper {
28 default ''; # Not approved
30 '~^Mozilla\/5\.0\ QGIS\/' 'QGIS';
33 # Limit Cache-Control header to only approved User-Agents
34 map $http_user_agent $limit_http_cache_control {
35 default ''; # Unset Header
36 '~^Mozilla\/5\.0\ QGIS\/' ''; # Unset Header
37 '~^Mozilla\/5\.0\ ' $http_cache_control; # Pass Header
40 # Limit Pragma header to only approved User-Agents
41 map $http_user_agent $limit_http_pragma {
42 default ''; # Unset Header
43 '~^Mozilla\/5\.0\ QGIS\/' ''; # Unset Header
44 '~^Mozilla\/5\.0\ ' $http_pragma; # Pass Header
48 listen 443 ssl fastopen=2048 http2 default_server;
49 server_name localhost;
53 ssl_certificate /etc/ssl/certs/tile.openstreetmap.org.pem;
54 ssl_certificate_key /etc/ssl/private/tile.openstreetmap.org.key;
57 proxy_pass http://tile_cache_backend;
58 proxy_set_header X-Forwarded-For $remote_addr;
59 proxy_http_version 1.1;
60 proxy_set_header Connection '';
62 proxy_connect_timeout 5s;
64 # Do not pass cookies to backends.
65 proxy_set_header Cookie '';
66 # Do not pass Accept-Encoding to backends.
67 proxy_set_header Accept-Encoding '';
69 # Do not allow setting cookies from backends due to caching.
70 proxy_ignore_headers Set-Cookie;
71 proxy_hide_header Set-Cookie;
73 # Set a QoS cookie if none presented (uses nginx Map)
74 add_header Set-Cookie $cookie_qos_token_set;
76 # QoS Traffic Rate see $limit_rate on http://nginx.org/en/docs/http/ngx_http_core_module.html
77 set $limit_rate $limit_rate_qos;
79 # Allow Higher Traffic Rate from Approved User-Agents which do not support cookies (uses nginx Map)
80 if ($approved_scraper) {
81 set $limit_rate 32768;
84 # Strip any ?query parameters from urls
87 # Allow cache purging headers only from select User-Agents (uses nginx Map)
88 proxy_set_header Cache-Control $limit_http_cache_control;
89 proxy_set_header Pragma $limit_http_pragma;