1 # DO NOT EDIT - This file is being maintained by Chef
3 upstream tile_cache_backend {
6 # Add the other caches to relieve pressure if local squid failing
7 # Balancer: round-robin
8 <% @caches.each do |cache| -%>
9 <% if cache[:hostname] != node[:hostname] -%>
10 # Server <%= cache[:hostname] %>
11 <% cache.ipaddresses(:family => :inet, :role => :external).sort.each do |address| -%>
12 server <%= address %> backup;
20 # Rates table based on current cookie value
21 map $cookie_qos_token $limit_rate_qos {
22 include /etc/nginx/conf.d/tile_qos_rates.map;
25 # Set-Cookie table based on current cookie value
26 map $cookie_qos_token $cookie_qos_token_set {
27 include /etc/nginx/conf.d/tile_qos_cookies.map;
30 map $http_user_agent $approved_scraper {
31 default ''; # Not approved
33 '~^Mozilla\/5\.0\ QGIS\/' 'QGIS';
36 map $http_user_agent $denied_scraper {
37 default ''; # Not denied
38 '~^Python\-urllib\/' 'Python';
44 map $http_referer $denied_referer {
45 default ''; # Not denied
46 'http://www.openstreetmap.org/' 'old-osm';
47 'http://www.osm.org/' 'old-osm';
48 'http://openstreetmap.org' 'fake-osm';
49 'http://www.openstreetmap.org' 'fake-osm';
52 # Limit Cache-Control header to only approved User-Agents
53 map $http_user_agent $limit_http_cache_control {
54 default ''; # Unset Header
55 '~^Mozilla\/5\.0\ QGIS\/' ''; # Unset Header
56 '~^Mozilla\/5\.0\ ' $http_cache_control; # Pass Header
59 # Limit Pragma header to only approved User-Agents
60 map $http_user_agent $limit_http_pragma {
61 default ''; # Unset Header
62 '~^Mozilla\/5\.0\ QGIS\/' ''; # Unset Header
63 '~^Mozilla\/5\.0\ ' $http_pragma; # Pass Header
67 listen 443 ssl fastopen=2048 http2 default_server;
68 server_name localhost;
72 ssl_certificate /etc/ssl/certs/tile.openstreetmap.org.pem;
73 ssl_certificate_key /etc/ssl/private/tile.openstreetmap.org.key;
76 proxy_pass http://tile_cache_backend;
77 proxy_set_header X-Forwarded-For $remote_addr;
78 proxy_http_version 1.1;
79 proxy_set_header Connection '';
81 proxy_connect_timeout 10s;
83 # Preserve host header.
84 proxy_set_header Host $host;
85 # Do not pass cookies to backends.
86 proxy_set_header Cookie '';
87 # Do not pass Accept-Encoding to backends.
88 proxy_set_header Accept-Encoding '';
90 # Do not allow setting cookies from backends due to caching.
91 proxy_ignore_headers Set-Cookie;
92 proxy_hide_header Set-Cookie;
94 # Set a QoS cookie if none presented (uses nginx Map)
95 add_header Set-Cookie $cookie_qos_token_set;
96 <% if node[:ssl][:strict_transport_security] -%>
97 # Ensure Strict-Transport-Security header is removed from proxied server responses
98 proxy_hide_header Strict-Transport-Security;
101 add_header Strict-Transport-Security "<%= node[:ssl][:strict_transport_security] %>" always;
104 # QoS Traffic Rate see $limit_rate on http://nginx.org/en/docs/http/ngx_http_core_module.html
105 set $limit_rate $limit_rate_qos;
107 # Allow Higher Traffic Rate from Approved User-Agents which do not support cookies (uses nginx Map)
108 if ($approved_scraper) {
109 set $limit_rate 65536;
112 if ($denied_scraper) {
115 if ($denied_referer) {
119 # Strip any ?query parameters from urls
122 # Allow cache purging headers only from select User-Agents (uses nginx Map)
123 proxy_set_header Cache-Control $limit_http_cache_control;
124 proxy_set_header Pragma $limit_http_pragma;