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