]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tilecache/templates/default/nginx_tile.conf.erb
Redirect http requests to https
[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:8080;
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;
10     <% end -%>
11     <% end -%>
12     <% end -%>
13
14     keepalive 32;
15 }
16
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;
20 }
21
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;
25 }
26
27 map $http_user_agent $approved_scraper {
28   default '';                       # Not approved
29   '~^JOSM\/' 'JOSM';
30   '~^Mozilla\/5\.0\ QGIS\/' 'QGIS';
31 }
32
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
38 }
39
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
45 }
46
47 server {
48     listen       443 ssl fastopen=2048 http2 default_server;
49     server_name  localhost;
50
51     proxy_buffers 8 64k;
52
53     ssl_certificate      /etc/ssl/certs/tile.openstreetmap.org.pem;
54     ssl_certificate_key  /etc/ssl/private/tile.openstreetmap.org.key;
55
56     location / {
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 '';
61
62       proxy_connect_timeout 5s;
63
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 '';
68
69       # Do not allow setting cookies from backends due to caching.
70       proxy_ignore_headers Set-Cookie;
71       proxy_hide_header Set-Cookie;
72
73       # Set a QoS cookie if none presented (uses nginx Map)
74       add_header Set-Cookie $cookie_qos_token_set;
75 <% if node[:ssl][:strict_transport_security] -%>
76       # Ensure Strict-Transport-Security header is removed from proxied server responses
77       proxy_hide_header Strict-Transport-Security;
78
79       # Enable HSTS
80       add_header Strict-Transport-Security "<%= node[:ssl][:strict_transport_security] %>" always;
81 <% end -%>
82
83       # QoS Traffic Rate see $limit_rate on http://nginx.org/en/docs/http/ngx_http_core_module.html
84       set $limit_rate $limit_rate_qos;
85
86       # Allow Higher Traffic Rate from Approved User-Agents which do not support cookies (uses nginx Map)
87       if ($approved_scraper) {
88         set $limit_rate 32768;
89       }
90
91       # Strip any ?query parameters from urls
92       set $args '';
93
94       # Allow cache purging headers only from select User-Agents (uses nginx Map)
95       proxy_set_header Cache-Control $limit_http_cache_control;
96       proxy_set_header Pragma $limit_http_pragma;
97     }
98 }
99
100 # Convert all http requests to https
101 server {
102     listen 80 default_server;
103     listen [::]:80 default_server;
104     server_name _;
105     return 301 https://$host$request_uri;
106 }