]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
526ec8dd7dac388e34c547671ddc0e11472826ae
[chef.git] / cookbooks / web / templates / default / apache.frontend.erb
1 # DO NOT EDIT - This file is being maintained by Chef
2
3 <% [80, 443].each do |port| -%>
4 <VirtualHost *:<%= port %>>
5   #
6   # Basic server configuration
7   #
8   ServerName <%= node[:fqdn] %>
9   ServerAlias api.openstreetmap.org www.openstreetmap.org
10   ServerAdmin webmaster@openstreetmap.org
11 <% if port == 443 -%>
12
13   #
14   # Enable SSL
15   #
16   SSLEngine on
17   SSLProxyEngine on
18 <% end -%>
19
20   #
21   # Setup logging
22   #
23   LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\" %Dus %{UNIQUE_ID}e %{SSL_PROTOCOL}x %{SSL_CIPHER}x" combined_with_time
24   CustomLog /var/log/apache2/access.log combined_with_time
25   ErrorLog /var/log/apache2/error.log
26
27   #
28   # Turn on various features
29   #
30   ExpiresActive On
31   RewriteEngine on
32
33   #
34   # Add the unique ID to the request headers
35   #
36   RequestHeader set X-Request-Id %{UNIQUE_ID}e
37
38   #
39   # Remove Proxy request header to mitigate https://httpoxy.org/
40   #
41   RequestHeader unset Proxy early
42
43   #
44   # Block troublesome GPX data scrapping
45   #
46   RewriteCond %{REQUEST_METHOD} HEAD
47   RewriteRule ^/trace/\d+/data - [F,L]
48
49   #
50   # Block tilesAtHome
51   #
52   RewriteCond %{HTTP_USER_AGENT} tilesAtHome
53   RewriteRule . - [F,L]
54
55   #
56   # Block changeset scraper
57   #
58   RewriteCond %{HTTP_USER_AGENT} "OSMApp Tuner"
59   RewriteRule . - [F,L]  
60
61   #
62   # Block requests for the old 404 map tile
63   #
64   RewriteRule ^/openlayers/img/404.png$ - [G,L]
65
66   #
67   # Block attempts to access old API versions
68   #
69   RewriteRule ^/api/0.[12345]/ - [G,L]
70
71   #
72   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
73   # lat/lon to be swapped (http://josm.openstreetmap.de/ticket/2804)
74   #
75   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
76   RewriteRule . - [F,L]
77
78   #
79   # Block a changeset that seems to lock things up
80   #
81   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
82
83   #
84   # Force special MIME type for crossdomain.xml files
85   #
86   <Files crossdomain.xml>
87     ForceType text/x-cross-domain-policy
88   </Files>
89
90   #
91   # Set expiry for assets
92   #
93   <Location /assets/>
94     Header unset Last-Modified
95     Header unset ETag
96     FileETag None
97
98     ExpiresDefault "access plus 1 year"
99   </Location>
100
101   #
102   # Set expiry for attachments
103   #
104   <Location /attachments/>
105     Header unset Last-Modified
106     Header unset ETag
107     FileETag None
108
109     ExpiresDefault "access plus 1 year"
110   </Location>
111
112   #
113   # Set expiry for other static content
114   #
115   <Location /export/embed.html>
116     ExpiresDefault "access plus 7 days"
117   </Location>
118   <Location /images/>
119     ExpiresDefault "access plus 10 years"
120   </Location>
121   <Location /javascripts/>
122     ExpiresDefault "access plus 10 years"
123   </Location>
124   <Location /openlayers/>
125     ExpiresDefault "access plus 7 days"
126   </Location>
127   <Location /stylesheets/>
128     ExpiresDefault "access plus 10 years"
129   </Location>
130
131   #
132   # Set expiry for Potlatch 1
133   #
134   <Location /potlatch/>
135     ExpiresDefault "access plus 7 days"
136   </Location>
137
138   #
139   # Set expiry for Potlatch 2
140   #
141   <Location /potlatch2/>
142     ExpiresByType application/x-shockwave-flash "access plus 1 day"
143     ExpiresByType application/xml "access plus 1 day"
144     ExpiresByType text/css "access plus 1 day"
145     ExpiresByType image/png "access plus 7 days"
146   </Location>
147
148   #
149   # Configure rails
150   #
151   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
152   RailsEnv production
153   PassengerMinInstances 10
154   PassengerMaxRequests 5000
155   PassengerMaxRequestQueueSize 250
156 <% if port == 443 -%>
157   PassengerPreStart https://www.openstreetmap.org/
158 <% else -%>
159   PassengerPreStart http://www.openstreetmap.org/
160 <% end -%>
161   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
162   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
163   Alias /openlayers <%= node[:web][:base_directory] %>/rails/vendor/assets/openlayers
164   Alias /stats /store/rails/stats
165   Alias /user/image /store/rails/user/image
166   Alias /attachments /store/rails/attachments
167
168   #
169   # Preserve the host name when forwarding to the proxy
170   #
171   ProxyPreserveHost on
172
173   #
174   # Set a long timeout - changeset uploads can take a long time
175   #
176   ProxyTimeout 3600
177
178   #
179   # Allow all proxy requests
180   #
181   <Proxy *>
182     Require all granted
183   </Proxy>
184
185   #
186   # Pass some other API calls to the backends via a load balancer
187   #
188   ProxyPass /api/0.6/map balancer://backend/api/0.6/map
189   ProxyPass /api/0.6/tracepoints balancer://backend/api/0.6/tracepoints
190   ProxyPass /api/0.6/amf/read balancer://backend/api/0.6/amf/read
191   ProxyPass /api/0.6/swf/trackpoints balancer://backend/api/0.6/swf/trackpoints
192   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+)$ balancer://backend$1
193   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/upload)$ balancer://bytemark$1
194   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/download)$ balancer://backend$1
195   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+)$ balancer://backend$1
196   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+/(full|history|search|ways))$ balancer://backend$1
197   ProxyPass /api/0.6/nodes balancer://backend/api/0.6/nodes
198   ProxyPass /api/0.6/ways balancer://backend/api/0.6/ways
199   ProxyPass /api/0.6/relations balancer://backend/api/0.6/relations
200   ProxyPassMatch ^(/trace/[0-9]+/data(|/|.xml))$ balancer://backend$1
201
202   #
203   # Redirect trac and wiki requests to the right places
204   #
205   RedirectPermanent /trac/ http://trac.openstreetmap.org/
206   RedirectPermanent /wiki/ http://wiki.openstreetmap.org/
207
208   #
209   # Redirect requests for various images to the right place
210   #
211   RedirectPermanent /images/osm_logo.png http://www.openstreetmap.org/assets/osm_logo.png
212   RedirectPermanent /images/cc_button.png http://www.openstreetmap.org/assets/cc_button.png
213
214   #
215   # Define a load balancer for the local backends
216   #
217   <Proxy balancer://backend>
218     ProxySet lbmethod=bybusyness
219 <% node[:web][:backends].each do |backend| -%>
220 <% if port == 443 -%>
221     BalancerMember https://<%= backend %> disablereuse=on
222 <% else -%>
223     BalancerMember http://<%= backend %>
224 <% end -%>
225 <% end -%>
226   </Proxy>
227
228   #
229   # Define a load balancer for the Bytemark backends
230   #
231   <Proxy balancer://bytemark>
232     ProxySet lbmethod=bybusyness
233 <% ["rails4.bm", "rails5.bm"].each do |backend| -%>
234 <% if port == 443 -%>
235     BalancerMember https://<%= backend %> disablereuse=on
236 <% else -%>
237     BalancerMember http://<%= backend %>
238 <% end -%>
239 <% end -%>
240   </Proxy>
241 <% if port == 80 -%>
242
243   #
244   # Redirect requests which should be secure to https
245   #
246   RewriteCond %{REQUEST_URI} ^/login(\.html)?$ [OR]
247   RewriteCond %{REQUEST_URI} ^/user/(new|create-account\.html)$ [OR]
248   RewriteCond %{REQUEST_URI} ^/user/terms$ [OR]
249   RewriteCond %{REQUEST_URI} ^/user/save$ [OR]
250   RewriteCond %{REQUEST_URI} ^/user/([^/]+)/account$ [OR]
251   RewriteCond %{REQUEST_URI} ^/user/reset-password$
252   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
253
254   #
255   # Redirect api requests made to www.osm.org to api.osm.org
256   #
257 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
258 #  RewriteRule ^/api/(.*)$ http://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
259
260   #
261   # Redirect non-api requests made to api.osm.org to www.osm.org
262   #
263   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
264   RewriteCond %{REQUEST_URI} !^/api/
265   RewriteRule ^(.*)$ http://www.openstreetmap.org$1 [L,NE,R=permanent]
266 <% elsif port == 443 -%>
267
268   #
269   # Redirect api requests made to www.osm.org to api.osm.org
270   #
271 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
272 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
273
274   #
275   # Redirect non-api requests made to api.osm.org to www.osm.org
276   #
277   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
278   RewriteCond %{REQUEST_URI} !^/api/
279   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
280 <% end -%>
281 </VirtualHost>
282
283 <% end -%>
284 <VirtualHost *:80>
285   ServerName openstreetmap.org
286   ServerAlias maps.openstreetmap.org mapz.openstreetmap.org
287   ServerAlias openstreetmap.com www.openstreetmap.com
288   ServerAlias maps.openstreetmap.com mapz.openstreetmap.com
289   ServerAlias openstreetmap.net www.openstreetmap.net
290   ServerAlias maps.openstreetmap.net mapz.openstreetmap.net
291   ServerAlias openstreetmap.ca www.openstreetmap.ca
292   ServerAlias maps.openstreetmap.ca mapz.openstreetmap.ca
293   ServerAlias openstreetmap.eu www.openstreetmap.eu
294   ServerAlias maps.openstreetmap.eu mapz.openstreetmap.eu
295   ServerAlias openstreetmap.pro www.openstreetmap.pro
296   ServerAlias maps.openstreetmap.pro mapz.openstreetmap.pro
297   ServerAlias openstreetmaps.org www.openstreetmaps.org
298   ServerAlias maps.openstreetmaps.org mapz.openstreetmaps.org
299   ServerAlias osm.org www.osm.org
300   ServerAlias maps.osm.org mapz.osm.org
301   ServerAlias openmaps.org www.openmaps.org
302   ServerAlias maps.openmaps.org mapz.openmaps.org
303   ServerAlias openstreetmap.io www.openstreetmap.io
304   ServerAlias maps.openstreetmap.io mapz.openstreetmap.io
305   ServerAlias osm.io www.osm.io
306   ServerAlias maps.osm.io mapz.osm.io
307   ServerAlias openworldmap.org www.openworldmap.org
308   ServerAlias maps.openworldmap.org mapz.openworldmap.org
309   ServerAlias freeosm.org www.freeosm.org
310   ServerAlias maps.freeosm.org mapz.freeosm.org
311   ServerAlias open-maps.org www.open-maps.org
312   ServerAlias maps.open-maps.org mapz.open-maps.org
313   ServerAlias open-maps.com www.open-maps.com
314   ServerAlias maps.open-maps.com mapz.open-maps.com
315   ServerAlias osmbugs.org www.osmbugs.org
316   ServerAlias maps.osmbugs.org mapz.osmbugs.org
317
318   #Third Party Sites
319   ServerAlias openstreetmap.pm www.openstreetmap.pm
320
321   RedirectPermanent / http://www.openstreetmap.org/
322 </VirtualHost>
323
324 <VirtualHost *:443>
325   ServerName openstreetmap.org
326   ServerAlias maps.openstreetmap.org mapz.openstreetmap.org
327
328   SSLEngine on
329
330   RedirectPermanent / https://www.openstreetmap.org/
331 </VirtualHost>
332
333 <VirtualHost *:80>
334   ServerName openstreetmap.org.uk
335   ServerAlias www.openstreetmap.org.uk
336   ServerAlias openstreetmap.co.uk
337   ServerAlias www.openstreetmap.co.uk
338
339   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
340   RedirectPermanent / http://www.openstreetmap.org/
341 </VirtualHost>
342
343 <Directory <%= node[:web][:base_directory] %>/rails/public>
344   Require all granted
345 </Directory>
346
347 <Directory /srv/www.openstreetmap.org/rails/app/assets>
348   Require all granted
349 </Directory>
350
351 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
352   Require all granted
353 </Directory>
354
355 <Directory /store/rails/stats>
356   Require all granted
357 </Directory>
358
359 <Directory /store/rails/user/image>
360   Require all granted
361 </Directory>
362
363 <Directory /store/rails/attachments>
364   Require all granted
365 </Directory>