]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
Use systemctl for gpx-import log rotation
[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 127.0.0.1
10   ServerAdmin webmaster@openstreetmap.org
11 <% if port == 443 -%>
12
13   #
14   # Enable SSL
15   #
16   SSLEngine on
17   SSLProxyEngine on
18   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
19   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
20 <% end -%>
21
22   #
23   # Setup logging
24   #
25   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
26   CustomLog /var/log/apache2/access.log combined_with_time
27   ErrorLog /var/log/apache2/error.log
28
29   #
30   # Turn on various features
31   #
32   ExpiresActive On
33   RewriteEngine on
34
35   #
36   # Add the unique ID to the request headers
37   #
38   RequestHeader set X-Request-Id %{UNIQUE_ID}e
39
40   #
41   # Remove Proxy request header to mitigate https://httpoxy.org/
42   #
43   RequestHeader unset Proxy early
44
45   #
46   # Block troublesome GPX data scrapping
47   #
48   RewriteCond %{REQUEST_METHOD} HEAD
49   RewriteRule ^/trace/\d+/data - [F,L]
50
51   #
52   # Block tilesAtHome
53   #
54   RewriteCond %{HTTP_USER_AGENT} tilesAtHome
55   RewriteRule . - [F,L]
56
57   #
58   # Block changeset scraper
59   #
60   RewriteCond %{HTTP_USER_AGENT} "OSMApp Tuner"
61   RewriteRule . - [F,L]
62
63   #
64   # Block requests for the old 404 map tile
65   #
66   RewriteRule ^/openlayers/img/404.png$ - [G,L]
67
68   #
69   # Block attempts to access old API versions
70   #
71   RewriteRule ^/api/0.[12345]/ - [G,L]
72
73   #
74   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
75   # lat/lon to be swapped (http://josm.openstreetmap.de/ticket/2804)
76   #
77   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
78   RewriteRule . - [F,L]
79
80   #
81   # Block a changeset that seems to lock things up
82   #
83   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
84
85   #
86   # Force special MIME type for crossdomain.xml files
87   #
88   <Files crossdomain.xml>
89     ForceType text/x-cross-domain-policy
90   </Files>
91
92   #
93   # Set expiry for assets
94   #
95   <Location /assets/>
96     Header unset Last-Modified
97     Header unset ETag
98     FileETag None
99
100     ExpiresDefault "access plus 1 year"
101   </Location>
102
103   #
104   # Set expiry for attachments
105   #
106   <Location /attachments/>
107     Header unset Last-Modified
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 <% if port == 443 -%>
159   PassengerPreStart https://www.openstreetmap.org/
160 <% else -%>
161   PassengerPreStart http://www.openstreetmap.org/
162 <% end -%>
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://bytemark$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 ACME certificate challenges
206   #
207   RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/
208
209   #
210   # Redirect trac and wiki requests to the right places
211   #
212   RedirectPermanent /trac/ http://trac.openstreetmap.org/
213   RedirectPermanent /wiki/ http://wiki.openstreetmap.org/
214
215   #
216   # Redirect requests for various images to the right place
217   #
218   RedirectPermanent /images/osm_logo.png http://www.openstreetmap.org/assets/osm_logo.png
219   RedirectPermanent /images/cc_button.png http://www.openstreetmap.org/assets/cc_button.png
220
221   #
222   # Define a load balancer for the local backends
223   #
224   <Proxy balancer://backend>
225     ProxySet lbmethod=bybusyness
226 <% node[:web][:backends].each do |backend| -%>
227 <% if port == 443 -%>
228     BalancerMember https://<%= backend %> disablereuse=on
229 <% else -%>
230     BalancerMember http://<%= backend %>
231 <% end -%>
232 <% end -%>
233   </Proxy>
234
235   #
236   # Define a load balancer for the Bytemark backends
237   #
238   <Proxy balancer://bytemark>
239     ProxySet lbmethod=bybusyness
240 <% ["rails4.bm", "rails5.bm"].each do |backend| -%>
241 <% if port == 443 -%>
242     BalancerMember https://<%= backend %> disablereuse=on
243 <% else -%>
244     BalancerMember http://<%= backend %>
245 <% end -%>
246 <% end -%>
247   </Proxy>
248 <% if port == 80 -%>
249
250   #
251   # Redirect requests which should be secure to https
252   #
253   RewriteCond %{REQUEST_URI} ^/login(\.html)?$ [OR]
254   RewriteCond %{REQUEST_URI} ^/user/(new|create-account\.html)$ [OR]
255   RewriteCond %{REQUEST_URI} ^/user/terms$ [OR]
256   RewriteCond %{REQUEST_URI} ^/user/save$ [OR]
257   RewriteCond %{REQUEST_URI} ^/user/([^/]+)/account$ [OR]
258   RewriteCond %{REQUEST_URI} ^/user/reset-password$
259   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
260
261   #
262   # Redirect api requests made to www.osm.org to api.osm.org
263   #
264 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
265 #  RewriteRule ^/api/(.*)$ http://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
266
267   #
268   # Redirect non-api requests made to api.osm.org to www.osm.org
269   #
270   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
271   RewriteCond %{REQUEST_URI} !^/api/
272   RewriteRule ^(.*)$ http://www.openstreetmap.org$1 [L,NE,R=permanent]
273 <% elsif port == 443 -%>
274
275   #
276   # Redirect api requests made to www.osm.org to api.osm.org
277   #
278 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
279 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
280
281   #
282   # Redirect non-api requests made to api.osm.org to www.osm.org
283   #
284   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
285   RewriteCond %{REQUEST_URI} !^/api/
286   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
287 <% end -%>
288 </VirtualHost>
289
290 <% end -%>
291 <VirtualHost *:80>
292   ServerName openstreetmap.org.uk
293   ServerAlias www.openstreetmap.org.uk
294   ServerAlias openstreetmap.co.uk
295   ServerAlias www.openstreetmap.co.uk
296
297   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
298   RedirectPermanent / http://www.openstreetmap.org/
299 </VirtualHost>
300
301 <VirtualHost *:80>
302   ServerName openstreetmap.org
303   ServerAlias *
304
305   RedirectPermanent / http://www.openstreetmap.org/
306 </VirtualHost>
307
308 <VirtualHost *:443>
309   ServerName openstreetmap.org
310   ServerAlias *
311
312   SSLEngine on
313   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
314   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
315
316   RedirectPermanent / https://www.openstreetmap.org/
317 </VirtualHost>
318
319 <Directory <%= node[:web][:base_directory] %>/rails/public>
320   Require all granted
321 </Directory>
322
323 <Directory /srv/www.openstreetmap.org/rails/app/assets>
324   Require all granted
325 </Directory>
326
327 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
328   Require all granted
329 </Directory>
330
331 <Directory /store/rails/stats>
332   Require all granted
333 </Directory>
334
335 <Directory /store/rails/user/image>
336   Require all granted
337 </Directory>
338
339 <Directory /store/rails/attachments>
340   Require all granted
341 </Directory>