]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tilecache/templates/default/nginx_tile.conf.erb
Merge remote-tracking branch 'github/pull/165'
[chef.git] / cookbooks / tilecache / templates / default / nginx_tile.conf.erb
1 # DO NOT EDIT - This file is being maintained by Chef
2
3 upstream tile_cache_backend {
4     server 127.0.0.1;
5
6     keepalive 32;
7 }
8
9 # Rates table based on current cookie value
10 map $cookie_qos_token $limit_rate_qos {
11   include /etc/nginx/conf.d/tile_qos_rates.map;
12 }
13
14 # Set-Cookie table based on current cookie value
15 map $cookie_qos_token $cookie_qos_token_set {
16   include /etc/nginx/conf.d/tile_qos_cookies.map;
17 }
18
19 map $http_user_agent $approved_scraper {
20   default '';                       # Not approved
21   '~^JOSM\/' 'JOSM';
22   '~^Mozilla\/5\.0\ QGIS\/' 'QGIS';
23 }
24
25 # Limit Cache-Control header to only approved User-Agents
26 map $http_user_agent $limit_http_cache_control {
27   default '';                              # Unset Header
28   '~^Mozilla\/5\.0\ QGIS\/' '';            # Unset Header
29   '~^Mozilla\/5\.0\ ' $http_cache_control; # Pass Header
30 }
31
32 # Limit Pragma header to only approved User-Agents
33 map $http_user_agent $limit_http_pragma {
34   default '';                       # Unset Header
35   '~^Mozilla\/5\.0\ QGIS\/' '';     # Unset Header
36   '~^Mozilla\/5\.0\ ' $http_pragma; # Pass Header
37 }
38
39 server {
40     listen       443 ssl fastopen=2048 http2 default_server;
41     server_name  localhost;
42
43     proxy_buffers 8 64k;
44
45     ssl_certificate      /etc/ssl/certs/tile.openstreetmap.org.pem;
46     ssl_certificate_key  /etc/ssl/private/tile.openstreetmap.org.key;
47
48     location / {
49       proxy_pass http://tile_cache_backend;
50       proxy_set_header X-Forwarded-For $remote_addr;
51       proxy_http_version 1.1;
52       proxy_set_header Connection '';
53
54       proxy_connect_timeout 5s;
55
56       # Preserve host header.
57       proxy_set_header Host $host;
58       # Do not pass cookies to backends.
59       proxy_set_header Cookie '';
60       # Do not pass Accept-Encoding to backends.
61       proxy_set_header Accept-Encoding '';
62
63       # Do not allow setting cookies from backends due to caching.
64       proxy_ignore_headers Set-Cookie;
65       proxy_hide_header Set-Cookie;
66
67       # Set a QoS cookie if none presented (uses nginx Map)
68       add_header Set-Cookie $cookie_qos_token_set;
69 <% if node[:ssl][:strict_transport_security] -%>
70       # Ensure Strict-Transport-Security header is removed from proxied server responses
71       proxy_hide_header Strict-Transport-Security;
72
73       # Enable HSTS
74       add_header Strict-Transport-Security "<%= node[:ssl][:strict_transport_security] %>" always;
75 <% end -%>
76
77       # QoS Traffic Rate see $limit_rate on http://nginx.org/en/docs/http/ngx_http_core_module.html
78       set $limit_rate $limit_rate_qos;
79
80       # Allow Higher Traffic Rate from Approved User-Agents which do not support cookies (uses nginx Map)
81       if ($approved_scraper) {
82         set $limit_rate 32768;
83       }
84
85       # Strip any ?query parameters from urls
86       set $args '';
87
88       # Allow cache purging headers only from select User-Agents (uses nginx Map)
89       proxy_set_header Cache-Control $limit_http_cache_control;
90       proxy_set_header Pragma $limit_http_pragma;
91     }
92 }