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