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