]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
web: ignore faulty Cloudflare rum posts
[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" 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 CF-Connecting-IP
31 <% @cloudflare.sort.each do |address| -%>
32   RemoteIPTrustedProxy <%= address %>
33 <% end -%>
34   # Fastly POPs
35 <% @fastly.sort.each do |address| -%>
36   RemoteIPTrustedProxy <%= address %>
37 <% end -%>
38
39   #
40   # Turn on various features
41   #
42   ExpiresActive On
43   RewriteEngine on
44
45   #
46   # Configure timeouts
47   #
48   RequestReadTimeout handshake=20-40,MinRate=500 header=20-40,MinRate=500 body=20-120,MinRate=500
49   LogLevel reqtimeout:info
50
51   #
52   # Add the unique ID to the request headers
53   #
54   RequestHeader set X-Request-Id %{UNIQUE_ID}e
55
56   #
57   # Remove Proxy request header to mitigate https://httpoxy.org/
58   #
59   RequestHeader unset Proxy early
60
61   #
62   # Block troublesome GPX data scrapping
63   #
64   RewriteCond %{REQUEST_METHOD} HEAD
65   RewriteRule ^/trace/\d+/data - [F,L]
66
67   #
68   # Block tilesAtHome
69   #
70   RewriteCond %{HTTP_USER_AGENT} tilesAtHome
71   RewriteRule . - [F,L]
72
73   #
74   # Block changeset scraper
75   #
76   RewriteCond %{HTTP_USER_AGENT} "OSMApp Tuner"
77   RewriteRule . - [F,L]
78
79   #
80   # Block trace scraper
81   #
82   RewriteCond %{HTTP_USER_AGENT} "python-httpx/0.24.1"
83   RewriteRule . - [F,L]
84
85   #
86   # Block out of control spider
87   #
88   RewriteCond %{HTTP_USER_AGENT} "Bytespider"
89   RewriteRule . - [F,L]
90
91   #
92   # Block attempts to access old API versions
93   #
94   RewriteRule ^/api/0.[12345]/ - [G,L]
95
96   #
97   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
98   # lat/lon to be swapped (https://josm.openstreetmap.de/ticket/2804)
99   #
100   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
101   RewriteRule . - [F,L]
102
103   #
104   # Block a changeset that seems to lock things up
105   #
106   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
107
108   #
109   # Ignore Vicon Valerus "online" status pings
110   # https://gist.github.com/Firefishy/86ed5b86991b225179b54bbafbcd769e
111   #
112   RewriteCond "%{QUERY_STRING}" "^q=abcde&t=20"
113   RewriteRule "^/api/0\.6/notes/search$" - [R=429,L]
114
115   #
116   # Ignore GoogleAssociationService request storm
117   # https://en.osm.town/@osm_tech/114205363076771822
118   #
119   RewriteCond %{HTTP_USER_AGENT} "GoogleAssociationService"
120   RewriteRule "^/\.well-known/assetlinks\.json$" - [R=429,L]
121
122   # Drop faulty Cloudflare POST /cdn-cgi/rum submissions reaching us
123   RewriteCond %{REQUEST_METHOD} =POST
124   RewriteRule ^/cdn-cgi/rum$ - [F,L]
125
126   #
127   # Force special MIME type for crossdomain.xml files
128   #
129   <Files crossdomain.xml>
130     ForceType text/x-cross-domain-policy
131   </Files>
132
133   #
134   # Set expiry for assets
135   #
136   <Location /assets/>
137     Header unset Last-Modified
138     FileETag Size
139
140     ExpiresDefault "access plus 1 year"
141     Header set Cache-Control "immutable, max-age=31536000" "expr=%{REQUEST_STATUS} == 200"
142   </Location>
143
144   #
145   # Set expiry for attachments
146   #
147   <Location /attachments/>
148     Header unset ETag
149     FileETag None
150
151     ExpiresDefault "access plus 1 year"
152   </Location>
153
154   #
155   # Set expiry for other static content
156   #
157   <Location /export/embed.html>
158     ExpiresDefault "access plus 7 days"
159   </Location>
160   <Location /images/>
161     ExpiresDefault "access plus 10 years"
162   </Location>
163   <Location /openlayers/>
164     Header unset Last-Modified
165     FileETag Size
166
167     Header always set Cache-Control "public, max-age=31536000, immutable"
168     Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
169   </Location>
170
171   #
172   # Configure rails
173   #
174   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
175   RailsEnv production
176   PassengerMinInstances 10
177   PassengerMaxRequests 5000
178   PassengerMaxRequestQueueSize 250
179   PassengerPreStart https://www.openstreetmap.org/
180   PassengerAppGroupName rails
181   SetEnv OPENSTREETMAP_STATUS <%= @status %>
182   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
183   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
184   Alias /openlayers <%= node[:web][:base_directory] %>/static/openlayers
185   Alias /funding.json <%= node[:web][:base_directory] %>/static/funding.json
186   Alias /.well-known/funding-manifest-urls <%= node[:web][:base_directory] %>/static/.well-known/funding-manifest-urls
187   Alias /.well-known/security.txt <%= node[:web][:base_directory] %>/static/.well-known/security.txt
188   Alias /security.txt <%= node[:web][:base_directory] %>/static/.well-known/security.txt
189   RedirectPermanent /stats https://planet.openstreetmap.org/statistics
190
191   #
192   # Pass authentication related headers to cgimap
193   #
194   <Location />
195     CGIPassAuth On
196   </Location>
197
198   #
199   # Normalise Accept-Encoding headers to workaround cgimap bug
200   #
201   RequestHeader edit* Accept-Encoding "\\s*,\\s*" ", "
202
203   #
204   # Disable deflate for applications that claim to handle it but can't
205   #
206   SetEnvIfNoCase User-Agent "StreetComplete" broken_deflate_client
207   SetEnvIfNoCase Referer "app:/resources/potlatch2.swf" broken_deflate_client
208   RequestHeader edit Accept-Encoding "deflate" "unsupported" env=broken_deflate_client
209
210   #
211   # Pass supported calls to cgimap
212   #
213   RewriteRule ^/api/0\.6/map(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
214   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
215   RewriteRule ^/api/0\.6/(node|way|relation|changeset)/[0-9]+(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
216   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/history(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
217   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/relations(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
218   RewriteRule ^/api/0\.6/node/[0-9]+/ways(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
219   RewriteRule ^/api/0\.6/(way|relation)/[0-9]+/full(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
220   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
221   RewriteRule ^/api/0\.6/(nodes|ways|relations)(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
222   RewriteRule ^/api/0\.6/changeset/[0-9]+/(upload|download)(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
223
224   #
225   # Redirect trac and wiki requests to the right places
226   #
227   RedirectPermanent /trac/ https://trac.openstreetmap.org/
228   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
229
230   #
231   # Redirect requests for various images to the right place
232   #
233   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
234   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
235
236   #
237   # Redirect api requests made to www.openstreetmap.org to api.openstreetmap.org
238   #
239 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
240 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
241
242   #
243   # Redirect non-api requests made to api.openstreetmap.org to www.openstreetmap.org
244   #
245   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
246   RewriteCond %{REQUEST_URI} !^/api/
247   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
248 </VirtualHost>
249
250 <VirtualHost *:80>
251   ServerName openstreetmap.org.uk
252   ServerAlias www.openstreetmap.org.uk
253   ServerAlias openstreetmap.co.uk
254   ServerAlias www.openstreetmap.co.uk
255
256   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
257   RedirectPermanent / https://www.openstreetmap.org/
258 </VirtualHost>
259
260 <VirtualHost *:80>
261   ServerName osm.org
262
263   Header always set Cache-Control "max-age=31536000"
264   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
265
266   RewriteEngine on
267
268   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
269
270   RewriteCond %{REQUEST_URI} !^/server-status$
271   RewriteRule ^(.*)$ https://osm.org$1 [L,NE,R=permanent]
272 </VirtualHost>
273
274 <VirtualHost *:80>
275   ServerName www.osm.org
276
277   Header always set Cache-Control "max-age=31536000"
278   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
279
280   RewriteEngine on
281
282   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
283
284   RewriteCond %{REQUEST_URI} !^/server-status$
285   RewriteRule ^(.*)$ https://www.osm.org$1 [L,NE,R=permanent]
286 </VirtualHost>
287
288 <VirtualHost *:80>
289   ServerName openstreetmap.org
290
291   Header always set Cache-Control "max-age=31536000"
292   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
293
294   RewriteEngine on
295
296   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
297
298   RewriteCond %{REQUEST_URI} !^/server-status$
299   RewriteRule ^(.*)$ https://openstreetmap.org$1 [L,NE,R=permanent]
300 </VirtualHost>
301
302 <VirtualHost *:80>
303   ServerName www.openstreetmap.org
304   ServerAlias *
305
306   Header always set Cache-Control "max-age=31536000"
307   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
308
309   RewriteEngine on
310
311   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
312
313   RewriteCond %{REQUEST_URI} !^/server-status$
314   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
315 </VirtualHost>
316
317 <VirtualHost *:443>
318   ServerName openstreetmap.org
319   ServerAlias *
320
321   SSLEngine on
322   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
323   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
324
325   Header always set Cache-Control "max-age=31536000"
326   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
327
328   RedirectPermanent / https://www.openstreetmap.org/
329 </VirtualHost>
330
331 <Directory <%= node[:web][:base_directory] %>/rails/public>
332   Require all granted
333
334   RewriteCond "%{HTTP:Accept-encoding}" "br"
335   RewriteCond "%{REQUEST_FILENAME}\.br" -s
336   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.br" [QSA]
337
338   RewriteCond "%{HTTP:Accept-encoding}" "gzip"
339   RewriteCond "%{REQUEST_FILENAME}\.gz" -s
340   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.gz" [QSA]
341
342   RewriteRule "\.css\.(br|gz)$" "-" [T=text/css,E=no-gzip:1,E=no-brotli:1]
343   RewriteRule "\.ico\.(br|gz)$"  "-" [T=image/vnd.microsoft.icon,E=no-gzip:1,E=no-brotli:1]
344   RewriteRule "\.js\.(br|gz)$"  "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
345   RewriteRule "\.json\.(br|gz)$"  "-" [T=application/json,E=no-gzip:1,E=no-brotli:1]
346   RewriteRule "\.svg\.(br|gz)$"  "-" [T=image/svg+xml,E=no-gzip:1,E=no-brotli:1]
347   RewriteRule "\.xml\.(br|gz)$"  "-" [T=application/xml,E=no-gzip:1,E=no-brotli:1]
348
349   <FilesMatch "\.(css|ico|js|json|svg|xml)\.br$">
350     Header append Content-Encoding br
351     Header append Vary Accept-Encoding
352   </FilesMatch>
353
354   <FilesMatch "\.(css|ico|js|json|svg|xml)\.gz$">
355     Header append Content-Encoding gzip
356     Header append Vary Accept-Encoding
357   </FilesMatch>
358 </Directory>
359
360 <Directory /srv/www.openstreetmap.org/static>
361   Require all granted
362
363   <Files "funding-manifest-urls">
364     ForceType text/plain
365   </Files>
366 </Directory>
367
368 <Directory /srv/www.openstreetmap.org/rails/app/assets>
369   Require all granted
370 </Directory>
371
372 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
373   Require all granted
374 </Directory>