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