]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
imagery: Add OS OpenMap Local April 2026
[chef.git] / cookbooks / web / templates / default / apache.frontend.erb
1 # DO NOT EDIT - This file is being maintained by Chef
2
3 #
4 # Setup logging
5 #
6 SetEnvIfNoCase Authorization "^Basic " AUTH_METHOD=basic
7 SetEnvIfNoCase Authorization "^OAuth " AUTH_METHOD=oauth1
8 SetEnvIfNoCase Authorization "^Bearer " AUTH_METHOD=oauth2
9 SetEnvIfExpr "%{QUERY_STRING} =~ /(^|&)oauth_signature=/" AUTH_METHOD=oauth1
10 LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %Dus %{UNIQUE_ID}e %{SSL_PROTOCOL}x %{SSL_CIPHER}x %{AUTH_METHOD}e \"%{X-TLS-JA4}i\" \"%{X-JA4H}i\"" combined_with_time
11 CustomLog /var/log/apache2/access.log combined_with_time
12 ErrorLog /var/log/apache2/error.log
13
14 <VirtualHost *:443>
15   #
16   # Basic server configuration
17   #
18   ServerName <%= node[:fqdn] %>
19   ServerAlias api.openstreetmap.org www.openstreetmap.org 127.0.0.1
20   ServerAdmin webmaster@openstreetmap.org
21
22   #
23   # Enable SSL
24   #
25   SSLEngine on
26   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
27   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
28
29   # Get the real remote IP for requests via a trusted proxy
30   RemoteIPHeader Fastly-Client-IP
31   # Fastly POPs
32 <% @fastly.sort.each do |address| -%>
33   RemoteIPTrustedProxy <%= address %>
34 <% end -%>
35
36   #
37   # Turn on various features
38   #
39   ExpiresActive On
40   RewriteEngine on
41
42   #
43   # Configure timeouts
44   #
45   RequestReadTimeout handshake=20-40,MinRate=500 header=20-40,MinRate=500 body=20-120,MinRate=500
46   LogLevel reqtimeout:info
47
48   #
49   # Add the unique ID to the request headers
50   #
51   RequestHeader set X-Request-Id %{UNIQUE_ID}e
52
53   #
54   # Remove Proxy request header to mitigate https://httpoxy.org/
55   #
56   RequestHeader unset Proxy early
57
58   #
59   # Block troublesome GPX data scrapping
60   #
61   RewriteCond %{REQUEST_METHOD} HEAD
62   RewriteRule ^/trace/\d+/data - [F,L]
63
64   #
65   # Block tilesAtHome
66   #
67   RewriteCond %{HTTP_USER_AGENT} tilesAtHome
68   RewriteRule . - [F,L]
69
70   #
71   # Block changeset scraper
72   #
73   RewriteCond %{HTTP_USER_AGENT} "OSMApp Tuner"
74   RewriteRule . - [F,L]
75
76   #
77   # Block trace scraper
78   #
79   RewriteCond %{HTTP_USER_AGENT} "python-httpx/0.24.1"
80   RewriteRule . - [F,L]
81
82   #
83   # Block out of control spider
84   #
85   RewriteCond %{HTTP_USER_AGENT} "Bytespider"
86   RewriteRule . - [F,L]
87
88   #
89   # Block attempts to access old API versions
90   #
91   RewriteRule ^/api/0.[12345]/ - [G,L]
92
93   #
94   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
95   # lat/lon to be swapped (https://josm.openstreetmap.de/ticket/2804)
96   #
97   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
98   RewriteRule . - [F,L]
99
100   #
101   # Block a changeset that seems to lock things up
102   #
103   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
104
105   #
106   # Ignore Vicon Valerus "online" status pings
107   # https://gist.github.com/Firefishy/86ed5b86991b225179b54bbafbcd769e
108   #
109   RewriteCond "%{QUERY_STRING}" "^q=abcde&t=20"
110   RewriteRule "^/api/0\.6/notes/search$" - [R=429,L]
111
112   #
113   # Ignore GoogleAssociationService request storm
114   # https://en.osm.town/@osm_tech/114205363076771822
115   #
116   RewriteCond %{HTTP_USER_AGENT} "GoogleAssociationService"
117   RewriteRule "^/\.well-known/assetlinks\.json$" - [R=429,L]
118
119   #
120   # Drop faulty Cloudflare POST /cdn-cgi/rum submissions reaching us
121   #
122   RewriteCond %{REQUEST_METHOD} =POST
123   RewriteRule ^/cdn-cgi/rum$ - [F,L]
124
125   #
126   # Block bogus referers
127   #
128   RewriteCond %{HTTP_REFERER} "^https://<%= Regexp.escape(node[:fqdn]) %>/"
129   RewriteRule . - [F,L]
130
131   #
132   # Block bogus user agents
133   #
134   # removed 2026-03-08, doesn't work with Fastly turning everything to http 1.1
135   # RewriteCond %{SERVER_PROTOCOL} =HTTP/1.1
136   # RewriteCond %{HTTP_USER_AGENT} Chrome/((103|105|107|108|109|110|111|112|116|117|120|124|131|133)\.0\.0\.0|104\.0\.5112\.81|106\.0\.5249\.119) [NC]
137   # RewriteRule . - [F,L]
138
139   #
140   # Redirect ACME certificate challenges (Fastly redirects from HTTP to HTTPS, so we need to handle them here)
141   #
142   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
143
144   #
145   # Force special MIME type for crossdomain.xml files
146   #
147   <Files crossdomain.xml>
148     ForceType text/x-cross-domain-policy
149   </Files>
150
151   #
152   # Set expiry for assets
153   #
154   <Location /assets/>
155     Header unset Last-Modified
156     FileETag Size
157
158     ExpiresDefault "access plus 1 year"
159     Header set Cache-Control "immutable, max-age=31536000" "expr=%{REQUEST_STATUS} == 200"
160   </Location>
161
162   #
163   # Set expiry for attachments
164   #
165   <Location /attachments/>
166     Header unset ETag
167     FileETag None
168
169     ExpiresDefault "access plus 1 year"
170   </Location>
171
172   #
173   # Set expiry for other static content
174   #
175   <Location /export/embed.html>
176     ExpiresDefault "access plus 7 days"
177   </Location>
178   <Location /images/>
179     ExpiresDefault "access plus 10 years"
180   </Location>
181   <Location /openlayers/>
182     Header unset Last-Modified
183     FileETag Size
184
185     Header always set Cache-Control "public, max-age=31536000, immutable"
186     Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
187   </Location>
188
189   #
190   # Configure rails
191   #
192   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
193   RailsEnv production
194   PassengerMinInstances 10
195   PassengerMaxRequests 5000
196   PassengerMaxRequestQueueSize 250
197   PassengerPreStart https://www.openstreetmap.org/
198   PassengerAppGroupName rails
199   SetEnv OPENSTREETMAP_STATUS <%= @status %>
200   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
201   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
202   Alias /openlayers <%= node[:web][:base_directory] %>/static/openlayers
203   Alias /funding.json <%= node[:web][:base_directory] %>/static/funding.json
204   Alias /.well-known/funding-manifest-urls <%= node[:web][:base_directory] %>/static/.well-known/funding-manifest-urls
205   Alias /.well-known/security.txt <%= node[:web][:base_directory] %>/static/.well-known/security.txt
206   Alias /security.txt <%= node[:web][:base_directory] %>/static/.well-known/security.txt
207   RedirectPermanent /stats https://planet.openstreetmap.org/statistics
208
209   #
210   # Pass authentication related headers to cgimap
211   #
212   <Location />
213     CGIPassAuth On
214   </Location>
215
216   #
217   # Normalise Accept-Encoding headers to workaround cgimap bug
218   #
219   RequestHeader edit* Accept-Encoding "\\s*,\\s*" ", "
220
221   #
222   # Disable deflate for applications that claim to handle it but can't
223   #
224   SetEnvIfNoCase User-Agent "StreetComplete" broken_deflate_client
225   SetEnvIfNoCase Referer "app:/resources/potlatch2.swf" broken_deflate_client
226   RequestHeader edit Accept-Encoding "deflate" "unsupported" env=broken_deflate_client
227
228   #
229   # Pass supported calls to cgimap
230   #
231   RewriteRule ^/api/0\.6/map(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
232   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
233   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
234   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/history(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
235   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/relations(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
236   RewriteRule ^/api/0\.6/node/[0-9]+/ways(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
237   RewriteRule ^/api/0\.6/(way|relation)/[0-9]+/full(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
238   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
239   RewriteRule ^/api/0\.6/(nodes|ways|relations)(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
240   RewriteRule ^/api/0\.6/changeset/[0-9]+/(upload|download)(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
241
242   #
243   # Redirect trac and wiki requests to the right places
244   #
245   RedirectPermanent /trac/ https://trac.openstreetmap.org/
246   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
247
248   #
249   # Redirect requests for various images to the right place
250   #
251   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
252   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
253
254   #
255   # Redirect api requests made to www.openstreetmap.org to api.openstreetmap.org
256   #
257 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
258 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
259
260   #
261   # Redirect non-api requests made to api.openstreetmap.org to www.openstreetmap.org
262   #
263   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
264   RewriteCond %{REQUEST_URI} !^/api/
265   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
266
267   # Restrict access to CDN nodes and admins
268   <Location />
269     Require expr "%{CONN_REMOTE_ADDR} != %{REMOTE_ADDR}"
270     # Fastly POPs
271 <% @fastly.sort.each do |address| -%>
272     Require ip <%= address %>
273 <% end -%>
274     # StatusCake monitoring
275 <% @statuscake.sort.reject { |address| address.empty? }.each do |address| -%>
276     Require ip <%= address %>
277 <% end -%>
278     # Administrators
279 <% @admins.sort.each do |address| -%>
280     Require ip <%= address %>
281 <% end -%>
282     # OSM Amsterdam IPv4 (he.net)
283     Require ip 184.104.179.128/27
284     # OSM Amsterdam IPv4 (equinix)
285     Require ip 82.199.86.96/27
286     # OSM Amsterdam IPv6 (he.net)
287     Require ip 2001:470:1:fa1::/64
288     # OSM Amsterdam IPv6 (equinix)
289     Require ip 2001:4d78:500:5e3::/64
290     # OSM Dublin IPv4 (he.net)
291     Require ip 184.104.226.96/27
292     # OSM Dublin IPv4 (equinix)
293     Require ip 87.252.214.96/27
294     # OSM Dublin IPv6 (he.net)
295     Require ip 2001:470:1:b3b::/64
296     # OSM Dublin IPv6 (equinix)
297     Require ip 2001:4d78:fe03:1c::/64
298     # OSM UCL IPv4
299     Require ip 193.60.236.0/24
300   </Location>
301 </VirtualHost>
302
303 <VirtualHost *:80>
304   ServerName openstreetmap.org.uk
305   ServerAlias www.openstreetmap.org.uk
306   ServerAlias openstreetmap.co.uk
307   ServerAlias www.openstreetmap.co.uk
308
309   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
310   RedirectPermanent / https://www.openstreetmap.org/
311 </VirtualHost>
312
313 <VirtualHost *:80>
314   ServerName osm.org
315
316   Header always set Cache-Control "max-age=31536000"
317   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
318
319   RewriteEngine on
320
321   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
322
323   RewriteCond %{REQUEST_URI} !^/server-status$
324   RewriteRule ^(.*)$ https://osm.org$1 [L,NE,R=permanent]
325 </VirtualHost>
326
327 <VirtualHost *:80>
328   ServerName www.osm.org
329
330   Header always set Cache-Control "max-age=31536000"
331   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
332
333   RewriteEngine on
334
335   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
336
337   RewriteCond %{REQUEST_URI} !^/server-status$
338   RewriteRule ^(.*)$ https://www.osm.org$1 [L,NE,R=permanent]
339 </VirtualHost>
340
341 <VirtualHost *:80>
342   ServerName openstreetmap.org
343
344   Header always set Cache-Control "max-age=31536000"
345   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
346
347   RewriteEngine on
348
349   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
350
351   RewriteCond %{REQUEST_URI} !^/server-status$
352   RewriteRule ^(.*)$ https://openstreetmap.org$1 [L,NE,R=permanent]
353 </VirtualHost>
354
355 <VirtualHost *:80>
356   ServerName www.openstreetmap.org
357   ServerAlias *
358
359   Header always set Cache-Control "max-age=31536000"
360   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
361
362   RewriteEngine on
363
364   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
365
366   RewriteCond %{REQUEST_URI} !^/server-status$
367   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
368 </VirtualHost>
369
370 <VirtualHost *:443>
371   ServerName openstreetmap.org
372   ServerAlias *
373
374   SSLEngine on
375   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
376   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
377
378   Header always set Cache-Control "max-age=31536000"
379   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
380
381   RedirectPermanent / https://www.openstreetmap.org/
382 </VirtualHost>
383
384 <Directory <%= node[:web][:base_directory] %>/rails/public>
385   Require all granted
386
387   RewriteCond "%{HTTP:Accept-encoding}" "br"
388   RewriteCond "%{REQUEST_FILENAME}\.br" -s
389   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.br" [QSA]
390
391   RewriteCond "%{HTTP:Accept-encoding}" "gzip"
392   RewriteCond "%{REQUEST_FILENAME}\.gz" -s
393   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.gz" [QSA]
394
395   RewriteRule "\.css\.(br|gz)$" "-" [T=text/css,E=no-gzip:1,E=no-brotli:1]
396   RewriteRule "\.ico\.(br|gz)$"  "-" [T=image/vnd.microsoft.icon,E=no-gzip:1,E=no-brotli:1]
397   RewriteRule "\.js\.(br|gz)$"  "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
398   RewriteRule "\.json\.(br|gz)$"  "-" [T=application/json,E=no-gzip:1,E=no-brotli:1]
399   RewriteRule "\.svg\.(br|gz)$"  "-" [T=image/svg+xml,E=no-gzip:1,E=no-brotli:1]
400   RewriteRule "\.xml\.(br|gz)$"  "-" [T=application/xml,E=no-gzip:1,E=no-brotli:1]
401
402   <FilesMatch "\.(css|ico|js|json|svg|xml)\.br$">
403     Header append Content-Encoding br
404     Header append Vary Accept-Encoding
405   </FilesMatch>
406
407   <FilesMatch "\.(css|ico|js|json|svg|xml)\.gz$">
408     Header append Content-Encoding gzip
409     Header append Vary Accept-Encoding
410   </FilesMatch>
411 </Directory>
412
413 <Directory /srv/www.openstreetmap.org/static>
414   Require all granted
415
416   <Files "funding-manifest-urls">
417     ForceType text/plain
418   </Files>
419 </Directory>
420
421 <Directory /srv/www.openstreetmap.org/rails/app/assets>
422   Require all granted
423 </Directory>
424
425 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
426   Require all granted
427 </Directory>