]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
Do all mod_deflate configuration in global context
[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     Allow from all
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 <% if port == 443 -%>
213     BalancerMember https://rails1 disablereuse=on
214     BalancerMember https://rails2 disablereuse=on
215     BalancerMember https://rails3 disablereuse=on
216 <% else -%>
217     BalancerMember http://rails1
218     BalancerMember http://rails2
219     BalancerMember http://rails3
220 <% end -%>
221   </Proxy>
222 <% if port == 80 -%>
223
224   #
225   # Redirect requests which should be secure to https
226   #
227   RewriteCond %{REQUEST_URI} ^/login(\.html)?$ [OR]
228   RewriteCond %{REQUEST_URI} ^/user/(new|create-account\.html)$ [OR]
229   RewriteCond %{REQUEST_URI} ^/user/terms$ [OR]
230   RewriteCond %{REQUEST_URI} ^/user/save$ [OR]
231   RewriteCond %{REQUEST_URI} ^/user/([^/]+)/account$ [OR]
232   RewriteCond %{REQUEST_URI} ^/user/reset-password$
233   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
234
235   #
236   # Redirect api requests made to www.osm.org to api.osm.org
237   #
238 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
239 #  RewriteRule ^/api/(.*)$ http://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
240
241   #
242   # Redirect non-api requests made to api.osm.org to www.osm.org
243   #
244   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
245   RewriteCond %{REQUEST_URI} !^/api/
246   RewriteRule ^(.*)$ http://www.openstreetmap.org$1 [L,NE,R=permanent]
247 <% elsif port == 443 -%>
248
249   #
250   # Redirect api requests made to www.osm.org to api.osm.org
251   #
252 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
253 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
254
255   #
256   # Redirect non-api requests made to api.osm.org to www.osm.org
257   #
258   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
259   RewriteCond %{REQUEST_URI} !^/api/
260   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
261 <% end -%>
262 </VirtualHost>
263
264 <% end -%>
265 <VirtualHost *:80>
266   ServerName openstreetmap.org
267   ServerAlias maps.openstreetmap.org mapz.openstreetmap.org
268   ServerAlias openstreetmap.com www.openstreetmap.com
269   ServerAlias maps.openstreetmap.com mapz.openstreetmap.com
270   ServerAlias openstreetmap.net www.openstreetmap.net
271   ServerAlias maps.openstreetmap.net mapz.openstreetmap.net
272   ServerAlias openstreetmap.ca www.openstreetmap.ca
273   ServerAlias maps.openstreetmap.ca mapz.openstreetmap.ca
274   ServerAlias openstreetmap.eu www.openstreetmap.eu
275   ServerAlias maps.openstreetmap.eu mapz.openstreetmap.eu
276   ServerAlias openstreetmap.pro www.openstreetmap.pro
277   ServerAlias maps.openstreetmap.pro mapz.openstreetmap.pro
278   ServerAlias openstreetmaps.org www.openstreetmaps.org
279   ServerAlias maps.openstreetmaps.org mapz.openstreetmaps.org
280   ServerAlias osm.org www.osm.org
281   ServerAlias maps.osm.org mapz.osm.org
282   ServerAlias openmaps.org www.openmaps.org
283   ServerAlias maps.openmaps.org mapz.openmaps.org
284   ServerAlias openstreetmap.io www.openstreetmap.io
285   ServerAlias maps.openstreetmap.io mapz.openstreetmap.io
286   ServerAlias osm.io www.osm.io
287   ServerAlias maps.osm.io mapz.osm.io
288   ServerAlias openworldmap.org www.openworldmap.org
289   ServerAlias maps.openworldmap.org mapz.openworldmap.org
290   ServerAlias freeosm.org www.freeosm.org
291   ServerAlias maps.freeosm.org mapz.freeosm.org
292   ServerAlias open-maps.org www.open-maps.org
293   ServerAlias maps.open-maps.org mapz.open-maps.org
294   ServerAlias open-maps.com www.open-maps.com
295   ServerAlias maps.open-maps.com mapz.open-maps.com
296   ServerAlias osmbugs.org www.osmbugs.org
297   ServerAlias maps.osmbugs.org mapz.osmbugs.org
298
299   #Third Party Sites
300   ServerAlias openstreetmap.pm www.openstreetmap.pm
301
302   RedirectPermanent / http://www.openstreetmap.org/
303 </VirtualHost>
304
305 <VirtualHost *:443>
306   ServerName openstreetmap.org
307   ServerAlias maps.openstreetmap.org mapz.openstreetmap.org
308
309   SSLEngine on
310
311   RedirectPermanent / https://www.openstreetmap.org/
312 </VirtualHost>
313
314 <VirtualHost *:80>
315   ServerName openstreetmap.org.uk
316   ServerAlias www.openstreetmap.org.uk
317   ServerAlias openstreetmap.co.uk
318   ServerAlias www.openstreetmap.co.uk
319
320   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
321   RedirectPermanent / http://www.openstreetmap.org/
322 </VirtualHost>
323
324 <Directory <%= node[:web][:base_directory] %>/rails/public>
325   Require all granted
326 </Directory>
327
328 <Directory /srv/www.openstreetmap.org/rails/app/assets>
329   Require all granted
330 </Directory>
331
332 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
333   Require all granted
334 </Directory>
335
336 <Directory /store/rails/stats>
337   Require all granted
338 </Directory>
339
340 <Directory /store/rails/user/image>
341   Require all granted
342 </Directory>
343
344 <Directory /store/rails/attachments>
345   Require all granted
346 </Directory>