]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
Add bogus user agent block
[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   RewriteCond %{SERVER_PROTOCOL} =HTTP/1.1
135   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]
136   RewriteRule . - [F,L]
137
138   #
139   # Force special MIME type for crossdomain.xml files
140   #
141   <Files crossdomain.xml>
142     ForceType text/x-cross-domain-policy
143   </Files>
144
145   #
146   # Set expiry for assets
147   #
148   <Location /assets/>
149     Header unset Last-Modified
150     FileETag Size
151
152     ExpiresDefault "access plus 1 year"
153     Header set Cache-Control "immutable, max-age=31536000" "expr=%{REQUEST_STATUS} == 200"
154   </Location>
155
156   #
157   # Set expiry for attachments
158   #
159   <Location /attachments/>
160     Header unset ETag
161     FileETag None
162
163     ExpiresDefault "access plus 1 year"
164   </Location>
165
166   #
167   # Set expiry for other static content
168   #
169   <Location /export/embed.html>
170     ExpiresDefault "access plus 7 days"
171   </Location>
172   <Location /images/>
173     ExpiresDefault "access plus 10 years"
174   </Location>
175   <Location /openlayers/>
176     Header unset Last-Modified
177     FileETag Size
178
179     Header always set Cache-Control "public, max-age=31536000, immutable"
180     Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
181   </Location>
182
183   #
184   # Configure rails
185   #
186   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
187   RailsEnv production
188   PassengerMinInstances 10
189   PassengerMaxRequests 5000
190   PassengerMaxRequestQueueSize 250
191   PassengerPreStart https://www.openstreetmap.org/
192   PassengerAppGroupName rails
193   SetEnv OPENSTREETMAP_STATUS <%= @status %>
194   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
195   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
196   Alias /openlayers <%= node[:web][:base_directory] %>/static/openlayers
197   Alias /funding.json <%= node[:web][:base_directory] %>/static/funding.json
198   Alias /.well-known/funding-manifest-urls <%= node[:web][:base_directory] %>/static/.well-known/funding-manifest-urls
199   Alias /.well-known/security.txt <%= node[:web][:base_directory] %>/static/.well-known/security.txt
200   Alias /security.txt <%= node[:web][:base_directory] %>/static/.well-known/security.txt
201   RedirectPermanent /stats https://planet.openstreetmap.org/statistics
202
203   #
204   # Pass authentication related headers to cgimap
205   #
206   <Location />
207     CGIPassAuth On
208   </Location>
209
210   #
211   # Normalise Accept-Encoding headers to workaround cgimap bug
212   #
213   RequestHeader edit* Accept-Encoding "\\s*,\\s*" ", "
214
215   #
216   # Disable deflate for applications that claim to handle it but can't
217   #
218   SetEnvIfNoCase User-Agent "StreetComplete" broken_deflate_client
219   SetEnvIfNoCase Referer "app:/resources/potlatch2.swf" broken_deflate_client
220   RequestHeader edit Accept-Encoding "deflate" "unsupported" env=broken_deflate_client
221
222   #
223   # Pass supported calls to cgimap
224   #
225   RewriteRule ^/api/0\.6/map(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
226   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
227   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
228   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/history(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
229   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/relations(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
230   RewriteRule ^/api/0\.6/node/[0-9]+/ways(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
231   RewriteRule ^/api/0\.6/(way|relation)/[0-9]+/full(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
232   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
233   RewriteRule ^/api/0\.6/(nodes|ways|relations)(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
234   RewriteRule ^/api/0\.6/changeset/[0-9]+/(upload|download)(\.json|\.xml)?$ unix:/run/cgimap/socket|fcgi://127.0.0.1$0 [P]
235
236   #
237   # Redirect trac and wiki requests to the right places
238   #
239   RedirectPermanent /trac/ https://trac.openstreetmap.org/
240   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
241
242   #
243   # Redirect requests for various images to the right place
244   #
245   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
246   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
247
248   #
249   # Redirect api requests made to www.openstreetmap.org to api.openstreetmap.org
250   #
251 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
252 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
253
254   #
255   # Redirect non-api requests made to api.openstreetmap.org to www.openstreetmap.org
256   #
257   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
258   RewriteCond %{REQUEST_URI} !^/api/
259   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
260 </VirtualHost>
261
262 <VirtualHost *:80>
263   ServerName openstreetmap.org.uk
264   ServerAlias www.openstreetmap.org.uk
265   ServerAlias openstreetmap.co.uk
266   ServerAlias www.openstreetmap.co.uk
267
268   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
269   RedirectPermanent / https://www.openstreetmap.org/
270 </VirtualHost>
271
272 <VirtualHost *:80>
273   ServerName osm.org
274
275   Header always set Cache-Control "max-age=31536000"
276   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
277
278   RewriteEngine on
279
280   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
281
282   RewriteCond %{REQUEST_URI} !^/server-status$
283   RewriteRule ^(.*)$ https://osm.org$1 [L,NE,R=permanent]
284 </VirtualHost>
285
286 <VirtualHost *:80>
287   ServerName www.osm.org
288
289   Header always set Cache-Control "max-age=31536000"
290   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
291
292   RewriteEngine on
293
294   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
295
296   RewriteCond %{REQUEST_URI} !^/server-status$
297   RewriteRule ^(.*)$ https://www.osm.org$1 [L,NE,R=permanent]
298 </VirtualHost>
299
300 <VirtualHost *:80>
301   ServerName openstreetmap.org
302
303   Header always set Cache-Control "max-age=31536000"
304   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
305
306   RewriteEngine on
307
308   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
309
310   RewriteCond %{REQUEST_URI} !^/server-status$
311   RewriteRule ^(.*)$ https://openstreetmap.org$1 [L,NE,R=permanent]
312 </VirtualHost>
313
314 <VirtualHost *:80>
315   ServerName www.openstreetmap.org
316   ServerAlias *
317
318   Header always set Cache-Control "max-age=31536000"
319   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
320
321   RewriteEngine on
322
323   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
324
325   RewriteCond %{REQUEST_URI} !^/server-status$
326   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
327 </VirtualHost>
328
329 <VirtualHost *:443>
330   ServerName openstreetmap.org
331   ServerAlias *
332
333   SSLEngine on
334   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
335   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
336
337   Header always set Cache-Control "max-age=31536000"
338   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
339
340   RedirectPermanent / https://www.openstreetmap.org/
341 </VirtualHost>
342
343 <Directory <%= node[:web][:base_directory] %>/rails/public>
344   Require all granted
345
346   RewriteCond "%{HTTP:Accept-encoding}" "br"
347   RewriteCond "%{REQUEST_FILENAME}\.br" -s
348   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.br" [QSA]
349
350   RewriteCond "%{HTTP:Accept-encoding}" "gzip"
351   RewriteCond "%{REQUEST_FILENAME}\.gz" -s
352   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.gz" [QSA]
353
354   RewriteRule "\.css\.(br|gz)$" "-" [T=text/css,E=no-gzip:1,E=no-brotli:1]
355   RewriteRule "\.ico\.(br|gz)$"  "-" [T=image/vnd.microsoft.icon,E=no-gzip:1,E=no-brotli:1]
356   RewriteRule "\.js\.(br|gz)$"  "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
357   RewriteRule "\.json\.(br|gz)$"  "-" [T=application/json,E=no-gzip:1,E=no-brotli:1]
358   RewriteRule "\.svg\.(br|gz)$"  "-" [T=image/svg+xml,E=no-gzip:1,E=no-brotli:1]
359   RewriteRule "\.xml\.(br|gz)$"  "-" [T=application/xml,E=no-gzip:1,E=no-brotli:1]
360
361   <FilesMatch "\.(css|ico|js|json|svg|xml)\.br$">
362     Header append Content-Encoding br
363     Header append Vary Accept-Encoding
364   </FilesMatch>
365
366   <FilesMatch "\.(css|ico|js|json|svg|xml)\.gz$">
367     Header append Content-Encoding gzip
368     Header append Vary Accept-Encoding
369   </FilesMatch>
370 </Directory>
371
372 <Directory /srv/www.openstreetmap.org/static>
373   Require all granted
374
375   <Files "funding-manifest-urls">
376     ForceType text/plain
377   </Files>
378 </Directory>
379
380 <Directory /srv/www.openstreetmap.org/rails/app/assets>
381   Require all granted
382 </Directory>
383
384 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
385   Require all granted
386 </Directory>