]> git.openstreetmap.org Git - chef.git/blob - cookbooks/tile/templates/default/apache.erb
Merge remote-tracking branch 'github/pull/550'
[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 POPs
72 <% @fastly.sort.each do |address| -%>
73     Require ip <%= address %>
74 <% end -%>
75     # StatusCake monitoring
76 <% @statuscake.sort.reject { |address| address.empty? }.each do |address| -%>
77     Require ip <%= address %>
78 <% end -%>
79     # Administrators
80 <% @admins.sort.each do |address| -%>
81     Require ip <%= address %>
82 <% end -%>
83     # OSM Amsterdam Cogent IPv4
84     Require ip 130.117.76.0/27
85     # OSM Amsterdam Cogent IPv6
86     Require ip 2001:978:2:2C::/64
87     # OSM Dublin IPv4
88     Require ip 184.104.226.96/27
89     # OSM Dublin IPv6
90     Require ip 2001:470:1:b3b::/64
91     # OSM UCL IPv4
92     Require ip 193.60.236.0/24
93   </LocationMatch>
94
95   # Internal endpoint for blocked users
96   <Location /blocked>
97     Header always set Cache-Control private
98     Redirect 429
99   </Location>
100 </VirtualHost>
101
102 <VirtualHost *:80>
103   # Basic server configuration
104   ServerName <%= node.name %>
105   ServerAlias tile.openstreetmap.org
106   ServerAlias render.openstreetmap.org
107   ServerAdmin webmaster@openstreetmap.org
108
109   # Setup logging
110   LogFormat "%a %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined_with_remoteip
111   CustomLog /var/log/apache2/access.log combined_with_remoteip
112   ErrorLog /var/log/apache2/error.log
113   BufferedLogs on
114
115   # Always set Access-Control-Allow-Origin so that simple CORS requests
116   # will always work and can be cached
117   Header set Access-Control-Allow-Origin "*"
118
119   # Add diagnostics header to identify render server
120   Header set X-TileRender "<%= node.name %>"
121
122   # Remove Proxy request header to mitigate https://httpoxy.org/
123   RequestHeader unset Proxy early
124
125   # Enable the rewrite engine
126   RewriteEngine on
127
128   # Redirect ACME certificate challenges
129   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
130
131   # Redirect to https
132   RewriteCond %{REQUEST_URI} !^/server-status$
133   RewriteCond %{REQUEST_URI} !^/mod_tile$
134   RewriteRule (.*) https://%{SERVER_NAME}/$1 [R=permanent,L]
135 </VirtualHost>
136
137 <Directory /srv/tile.openstreetmap.org/html>
138   Options None
139   AllowOverride None
140   Require all granted
141 </Directory>
142
143 <Directory /srv/tile.openstreetmap.org/cgi-bin>
144   Options ExecCGI
145   AllowOverride None
146   Require all granted
147 </Directory>