]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tile/templates/default/apache.erb
Block requests for tiles unless they come from a CDN node
[chef.git] / cookbooks / tile / templates / default / apache.erb
1 # DO NOT EDIT - This file is being maintained by Chef
2
3 <VirtualHost *:443>
4   # Basic server configuration
5   ServerName <%= node.name %>
6   ServerAlias tile.openstreetmap.org
7   ServerAlias render.openstreetmap.org
8   ServerAdmin webmaster@openstreetmap.org
9
10   #
11   # Enable SSL
12   #
13   SSLEngine on
14   SSLProxyEngine on
15   SSLCertificateFile /etc/ssl/certs/<%= node[:fqdn] %>.pem
16   SSLCertificateKeyFile /etc/ssl/private/<%= node[:fqdn] %>.key
17
18   # Configure location of static files and CGI scripts
19   DocumentRoot /srv/tile.openstreetmap.org/html
20   ScriptAlias /cgi-bin/ /srv/tile.openstreetmap.org/cgi-bin/
21
22   # Setup logging
23   LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_remoteip
24   CustomLog /var/log/apache2/access.log combined_with_remoteip
25   ErrorLog /var/log/apache2/error.log
26   BufferedLogs on
27
28   # Always set Access-Control-Allow-Origin so that simple CORS requests
29   # will always work and can be cached
30   Header set Access-Control-Allow-Origin "*"
31
32   # Add diagnostics header to identify render server
33   Header set X-TileRender "<%= node.name %>"
34
35   # Tell clients to use stale tiles if necessary
36   Header append Cache-Control "stale-while-revalidate=604800, stale-if-error=604800" "expr=%{CONTENT_TYPE} == 'image/png'"
37
38   # Remove Proxy request header to mitigate https://httpoxy.org/
39   RequestHeader unset Proxy early
40
41   # Enable the rewrite engine
42   RewriteEngine on
43
44   # Rewrite tile requests to the default style
45   RewriteRule ^/(\d+)/(\d+)/(\d+)\.png$ /default/$1/$2/$3.png [PT,T=image/png,L]
46   RewriteRule ^/(\d+)/(\d+)/(\d+)\.png/status/?$  /default/$1/$2/$3.png/status [PT,T=text/plain,L]
47   RewriteRule ^/(\d+)/(\d+)/(\d+)\.png/dirty/?$   /default/$1/$2/$3.png/dirty  [PT,T=text/plain,L]
48
49   # Historical Files redirect
50   RedirectPermanent /processed_p.tar.bz2 https://planet.openstreetmap.org/historical-shapefiles/
51   RedirectPermanent /shoreline_300.tar.bz2 https://planet.openstreetmap.org/historical-shapefiles/
52   RedirectPermanent /world_boundaries-spherical.tgz https://planet.openstreetmap.org/historical-shapefiles/
53
54   # Redirect ACME certificate challenges
55   RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/
56
57   # Restrict tile access to CDN nodes and admins
58   <LocationMatch ^/default/\d+/\d+/\d+\.png$>
59 <% @fastly.sort.each do |address| -%>
60     Require ip <%= address %>
61 <% end -%>
62 <% @statuscake.sort.reject { |address| address.empty? }.each do |address| -%>
63     Require ip <%= address %>
64 <% end -%>
65 <% @admins.sort.each do |address| -%>
66     Require ip <%= address %>
67 <% end -%>
68     Require ip 130.117.76.0/27
69     Require ip 2001:978:2:2C::/64
70     Require ip 184.104.226.96/27
71     Require ip 2001:470:1:b3b::/64
72     Require ip 193.60.236.0/24
73   </LocationMatch>
74
75   # Get the real remote IP for requests via a trusted proxy
76   RemoteIPHeader Fastly-Client-IP
77 <% @fastly.sort.each do |address| -%>
78   RemoteIPTrustedProxy <%= address %>
79 <% end -%>
80
81   # Enforce rate limits
82   RewriteMap ipmap txt:/srv/tile.openstreetmap.org/conf/ip.map
83   RewriteCond ${ipmap:%{REMOTE_ADDR}} ^.+$
84   RewriteRule ^.*$ /${ipmap:%{REMOTE_ADDR}} [PT]
85
86   # Internal endpoint for blocked users
87   <Location /blocked>
88     Header always set Cache-Control private
89     Redirect 429
90   </Location>
91 </VirtualHost>
92
93 <VirtualHost *:80>
94   # Basic server configuration
95   ServerName <%= node.name %>
96   ServerAlias tile.openstreetmap.org
97   ServerAlias render.openstreetmap.org
98   ServerAdmin webmaster@openstreetmap.org
99
100   # Setup logging
101   LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_remoteip
102   CustomLog /var/log/apache2/access.log combined_with_remoteip
103   ErrorLog /var/log/apache2/error.log
104   BufferedLogs on
105
106   # Always set Access-Control-Allow-Origin so that simple CORS requests
107   # will always work and can be cached
108   Header set Access-Control-Allow-Origin "*"
109
110   # Add diagnostics header to identify render server
111   Header set X-TileRender "<%= node.name %>"
112
113   # Remove Proxy request header to mitigate https://httpoxy.org/
114   RequestHeader unset Proxy early
115
116   # Enable the rewrite engine
117   RewriteEngine on
118
119   # Redirect ACME certificate challenges
120   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
121
122   # Redirect to https
123   RewriteCond %{REQUEST_URI} !^/server-status$
124   RewriteCond %{REQUEST_URI} !^/mod_tile$
125   RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=permanent,L]
126 </VirtualHost>
127
128 <Directory /srv/tile.openstreetmap.org/html>
129   Options None
130   AllowOverride None
131   Require all granted
132 </Directory>
133
134 <Directory /srv/tile.openstreetmap.org/cgi-bin>
135   Options ExecCGI
136   AllowOverride None
137   Require all granted
138 </Directory>