]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
Redirect http to https for the main web site
[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   #
63   RewriteRule ^/openlayers/img/404.png$ - [G,L]
64
65   #
66   # Block attempts to access old API versions
67   #
68   RewriteRule ^/api/0.[12345]/ - [G,L]
69
70   #
71   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
72   # lat/lon to be swapped (https://josm.openstreetmap.de/ticket/2804)
73   #
74   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
75   RewriteRule . - [F,L]
76
77   #
78   # Block a changeset that seems to lock things up
79   #
80   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
81
82   #
83   # Force special MIME type for crossdomain.xml files
84   #
85   <Files crossdomain.xml>
86     ForceType text/x-cross-domain-policy
87   </Files>
88
89   #
90   # Set expiry for assets
91   #
92   <Location /assets/>
93     Header unset Last-Modified
94     Header unset ETag
95     FileETag None
96
97     ExpiresDefault "access plus 1 year"
98   </Location>
99
100   #
101   # Set expiry for attachments
102   #
103   <Location /attachments/>
104     Header unset Last-Modified
105     Header unset ETag
106     FileETag None
107
108     ExpiresDefault "access plus 1 year"
109   </Location>
110
111   #
112   # Set expiry for other static content
113   #
114   <Location /export/embed.html>
115     ExpiresDefault "access plus 7 days"
116   </Location>
117   <Location /images/>
118     ExpiresDefault "access plus 10 years"
119   </Location>
120   <Location /javascripts/>
121     ExpiresDefault "access plus 10 years"
122   </Location>
123   <Location /openlayers/>
124     ExpiresDefault "access plus 7 days"
125   </Location>
126   <Location /stylesheets/>
127     ExpiresDefault "access plus 10 years"
128   </Location>
129
130   #
131   # Set expiry for Potlatch 1
132   #
133   <Location /potlatch/>
134     ExpiresDefault "access plus 7 days"
135   </Location>
136
137   #
138   # Set expiry for Potlatch 2
139   #
140   <Location /potlatch2/>
141     ExpiresByType application/x-shockwave-flash "access plus 1 day"
142     ExpiresByType application/xml "access plus 1 day"
143     ExpiresByType text/css "access plus 1 day"
144     ExpiresByType image/png "access plus 7 days"
145   </Location>
146
147   #
148   # Configure rails
149   #
150   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
151   RailsEnv production
152   PassengerMinInstances 10
153   PassengerMaxRequests 5000
154   PassengerMaxRequestQueueSize 250
155   PassengerPreStart https://www.openstreetmap.org/
156   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
157   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
158   Alias /openlayers <%= node[:web][:base_directory] %>/rails/vendor/assets/openlayers
159   Alias /stats /store/rails/stats
160   Alias /user/image /store/rails/user/image
161   Alias /attachments /store/rails/attachments
162
163   #
164   # Preserve the host name when forwarding to the proxy
165   #
166   ProxyPreserveHost on
167
168   #
169   # Set a long timeout - changeset uploads can take a long time
170   #
171   ProxyTimeout 3600
172
173   #
174   # Allow all proxy requests
175   #
176   <Proxy *>
177     Require all granted
178   </Proxy>
179
180   #
181   # Pass some other API calls to the backends via a load balancer
182   #
183   ProxyPass /api/0.6/map balancer://backend/api/0.6/map
184   ProxyPass /api/0.6/tracepoints balancer://backend/api/0.6/tracepoints
185   ProxyPass /api/0.6/amf/read balancer://backend/api/0.6/amf/read
186   ProxyPass /api/0.6/swf/trackpoints balancer://backend/api/0.6/swf/trackpoints
187   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+)$ balancer://backend$1
188   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/upload)$ balancer://ic$1
189   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/download)$ balancer://backend$1
190   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+)$ balancer://backend$1
191   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+/(full|history|search|ways))$ balancer://backend$1
192   ProxyPass /api/0.6/nodes balancer://backend/api/0.6/nodes
193   ProxyPass /api/0.6/ways balancer://backend/api/0.6/ways
194   ProxyPass /api/0.6/relations balancer://backend/api/0.6/relations
195   ProxyPassMatch ^(/trace/[0-9]+/data(|/|.xml))$ balancer://backend$1
196
197   #
198   # Redirect trac and wiki requests to the right places
199   #
200   RedirectPermanent /trac/ https://trac.openstreetmap.org/
201   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
202
203   #
204   # Redirect requests for various images to the right place
205   #
206   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
207   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
208
209   #
210   # Define a load balancer for the local backends
211   #
212   <Proxy balancer://backend>
213     ProxySet lbmethod=bybusyness
214 <% node[:web][:backends].each do |backend| -%>
215     BalancerMember https://<%= backend %> disablereuse=on
216 <% end -%>
217   </Proxy>
218
219   #
220   # Define a load balancer for the IC backends
221   #
222   <Proxy balancer://ic>
223     ProxySet lbmethod=bybusyness
224 <% ["rails1.ic", "rails2.ic", "rails3.ic"].each do |backend| -%>
225     BalancerMember https://<%= backend %> disablereuse=on
226 <% end -%>
227   </Proxy>
228
229   #
230   # Redirect api requests made to www.osm.org to api.osm.org
231   #
232 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
233 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
234
235   #
236   # Redirect non-api requests made to api.osm.org to www.osm.org
237   #
238   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
239   RewriteCond %{REQUEST_URI} !^/api/
240   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
241 </VirtualHost>
242
243 <VirtualHost *:80>
244   ServerName openstreetmap.org.uk
245   ServerAlias www.openstreetmap.org.uk
246   ServerAlias openstreetmap.co.uk
247   ServerAlias www.openstreetmap.co.uk
248
249   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
250   RedirectPermanent / https://www.openstreetmap.org/
251 </VirtualHost>
252
253 <VirtualHost *:80>
254   ServerName openstreetmap.org
255   ServerAlias *
256
257   RewriteEngine on
258
259   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
260
261   RewriteCond %{REQUEST_URI} !^/server-status$
262   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
263 </VirtualHost>
264
265 <VirtualHost *:443>
266   ServerName openstreetmap.org
267   ServerAlias *
268
269   SSLEngine on
270   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
271   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
272
273   RedirectPermanent / https://www.openstreetmap.org/
274 </VirtualHost>
275
276 <Directory <%= node[:web][:base_directory] %>/rails/public>
277   Require all granted
278 </Directory>
279
280 <Directory /srv/www.openstreetmap.org/rails/app/assets>
281   Require all granted
282 </Directory>
283
284 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
285   Require all granted
286 </Directory>
287
288 <Directory /store/rails/stats>
289   Require all granted
290 </Directory>
291
292 <Directory /store/rails/user/image>
293   Require all granted
294 </Directory>
295
296 <Directory /store/rails/attachments>
297   Require all granted
298 </Directory>