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