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