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