]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
08489dc86fd4b028454eccb38340cff381b0b85f
[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 ETag
99     FileETag None
100
101     ExpiresDefault "access plus 1 year"
102   </Location>
103
104   #
105   # Set expiry for attachments
106   #
107   <Location /attachments/>
108     Header unset ETag
109     FileETag None
110
111     ExpiresDefault "access plus 1 year"
112   </Location>
113
114   #
115   # Set expiry for other static content
116   #
117   <Location /export/embed.html>
118     ExpiresDefault "access plus 7 days"
119   </Location>
120   <Location /images/>
121     ExpiresDefault "access plus 10 years"
122   </Location>
123   <Location /javascripts/>
124     ExpiresDefault "access plus 10 years"
125   </Location>
126   <Location /openlayers/>
127     ExpiresDefault "access plus 7 days"
128   </Location>
129   <Location /stylesheets/>
130     ExpiresDefault "access plus 10 years"
131   </Location>
132
133   #
134   # Set expiry for Potlatch 1
135   #
136   <Location /potlatch/>
137     ExpiresDefault "access plus 7 days"
138   </Location>
139
140   #
141   # Set expiry for Potlatch 2
142   #
143   <Location /potlatch2/>
144     ExpiresByType application/x-shockwave-flash "access plus 1 day"
145     ExpiresByType application/xml "access plus 1 day"
146     ExpiresByType text/css "access plus 1 day"
147     ExpiresByType image/png "access plus 7 days"
148   </Location>
149
150   #
151   # Configure rails
152   #
153   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
154   RailsEnv production
155   PassengerMinInstances 10
156   PassengerMaxRequests 5000
157   PassengerMaxRequestQueueSize 250
158   PassengerPreStart https://www.openstreetmap.org/
159   PassengerAppGroupName rails
160   SetEnv OPENSTREETMAP_STATUS <%= @status %>
161   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
162   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
163   Alias /openlayers <%= node[:web][:base_directory] %>/rails/vendor/assets/openlayers
164   Alias /stats /store/rails/stats
165   Alias /user/image /store/rails/user/image
166   Alias /attachments /store/rails/attachments
167
168   #
169   # Preserve the host name when forwarding to the proxy
170   #
171   ProxyPreserveHost on
172
173   #
174   # Set a long timeout - changeset uploads can take a long time
175   #
176   ProxyTimeout 3600
177
178   #
179   # Allow all proxy requests
180   #
181   <Proxy *>
182     Require all granted
183   </Proxy>
184
185   #
186   # Pass some other API calls to the backends via a load balancer
187   #
188   ProxyPass /api/0.6/map balancer://backend/api/0.6/map
189   ProxyPass /api/0.6/tracepoints balancer://backend/api/0.6/tracepoints
190   ProxyPass /api/0.6/amf/read balancer://backend/api/0.6/amf/read
191   ProxyPass /api/0.6/swf/trackpoints balancer://backend/api/0.6/swf/trackpoints
192   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+)$ balancer://backend$1
193   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/upload)$ balancer://amsterdam$1
194   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/download)$ balancer://backend$1
195   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+)$ balancer://backend$1
196   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+/(full|history|search|ways))$ balancer://backend$1
197   ProxyPass /api/0.6/nodes balancer://backend/api/0.6/nodes
198   ProxyPass /api/0.6/ways balancer://backend/api/0.6/ways
199   ProxyPass /api/0.6/relations balancer://backend/api/0.6/relations
200   ProxyPassMatch ^(/trace/[0-9]+/data(|/|.xml))$ balancer://backend$1
201
202   #
203   # Redirect trac and wiki requests to the right places
204   #
205   RedirectPermanent /trac/ https://trac.openstreetmap.org/
206   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
207
208   #
209   # Redirect requests for various images to the right place
210   #
211   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
212   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
213
214   #
215   # Define a load balancer for the local backends
216   #
217   <Proxy balancer://backend>
218     ProxySet lbmethod=bybusyness
219 <% node[:web][:backends].each do |backend| -%>
220     BalancerMember https://<%= backend %> disablereuse=on
221 <% end -%>
222   </Proxy>
223
224   #
225   # Define a load balancer for the Amsterdam backends
226   #
227   <Proxy balancer://amsterdam>
228     ProxySet lbmethod=bybusyness
229 <% ["rails1.ams", "rails2.ams", "rails3.ams"].each do |backend| -%>
230     BalancerMember https://<%= backend %> disablereuse=on
231 <% end -%>
232   </Proxy>
233
234   #
235   # Define a load balancer for the Bytemark backends
236   #
237   <Proxy balancer://bytemark>
238     ProxySet lbmethod=bybusyness
239 <% ["rails4.bm", "rails5.bm"].each do |backend| -%>
240     BalancerMember https://<%= backend %> disablereuse=on
241 <% end -%>
242   </Proxy>
243
244   #
245   # Redirect api requests made to www.osm.org to api.osm.org
246   #
247 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
248 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
249
250   #
251   # Redirect non-api requests made to api.osm.org to www.osm.org
252   #
253   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
254   RewriteCond %{REQUEST_URI} !^/api/
255   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
256 </VirtualHost>
257
258 <VirtualHost *:80>
259   ServerName openstreetmap.org.uk
260   ServerAlias www.openstreetmap.org.uk
261   ServerAlias openstreetmap.co.uk
262   ServerAlias www.openstreetmap.co.uk
263
264   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
265   RedirectPermanent / https://www.openstreetmap.org/
266 </VirtualHost>
267
268 <VirtualHost *:80>
269   ServerName openstreetmap.org
270
271   Header always set Cache-Control "max-age=31536000"
272   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
273
274   RewriteEngine on
275
276   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
277
278   RewriteCond %{REQUEST_URI} !^/server-status$
279   RewriteRule ^(.*)$ https://openstreetmap.org$1 [L,NE,R=permanent]
280 </VirtualHost>
281
282 <VirtualHost *:80>
283   ServerName www.openstreetmap.org
284   ServerAlias *
285
286   Header always set Cache-Control "max-age=31536000"
287   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
288
289   RewriteEngine on
290
291   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
292
293   RewriteCond %{REQUEST_URI} !^/server-status$
294   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
295 </VirtualHost>
296
297 <VirtualHost *:443>
298   ServerName openstreetmap.org
299   ServerAlias *
300
301   SSLEngine on
302   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
303   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
304
305   Header always set Cache-Control "max-age=31536000"
306   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
307
308   RedirectPermanent / https://www.openstreetmap.org/
309 </VirtualHost>
310
311 <Directory <%= node[:web][:base_directory] %>/rails/public>
312   Require all granted
313 </Directory>
314
315 <Directory /srv/www.openstreetmap.org/rails/app/assets>
316   Require all granted
317 </Directory>
318
319 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
320   Require all granted
321 </Directory>
322
323 <Directory /store/rails/stats>
324   Require all granted
325 </Directory>
326
327 <Directory /store/rails/user/image>
328   Require all granted
329 </Directory>
330
331 <Directory /store/rails/attachments>
332   Require all granted
333 </Directory>