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