]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
Merge remote-tracking branch 'github/pull/528'
[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   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
16   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
17
18   #
19   # Setup logging
20   #
21   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
22   CustomLog /var/log/apache2/access.log combined_with_time
23   CustomLog /var/log/apache2/basic.log combined_with_time "expr=%{HTTP:Authorization} =~ /^Basic/i"
24   ErrorLog /var/log/apache2/error.log
25
26   #
27   # Turn on various features
28   #
29   ExpiresActive On
30   RewriteEngine on
31
32   #
33   # Configure timeouts
34   #
35   RequestReadTimeout handshake=20-40,MinRate=500 header=20-40,MinRate=500 body=20,MinRate=500
36
37   #
38   # Add the unique ID to the request headers
39   #
40   RequestHeader set X-Request-Id %{UNIQUE_ID}e
41
42   #
43   # Remove Proxy request header to mitigate https://httpoxy.org/
44   #
45   RequestHeader unset Proxy early
46
47   #
48   # Block troublesome GPX data scrapping
49   #
50   RewriteCond %{REQUEST_METHOD} HEAD
51   RewriteRule ^/trace/\d+/data - [F,L]
52
53   #
54   # Block tilesAtHome
55   #
56   RewriteCond %{HTTP_USER_AGENT} tilesAtHome
57   RewriteRule . - [F,L]
58
59   #
60   # Block changeset scraper
61   #
62   RewriteCond %{HTTP_USER_AGENT} "OSMApp Tuner"
63   RewriteRule . - [F,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   # Ignore Vicon Valerus "online" status pings
84   # https://gist.github.com/Firefishy/86ed5b86991b225179b54bbafbcd769e
85   #
86   RewriteCond "%{QUERY_STRING}" "^q=abcde&t=20"
87   RewriteRule "^/api/0\.6/notes/search$" - [R=429,L]
88
89   #
90   # Force special MIME type for crossdomain.xml files
91   #
92   <Files crossdomain.xml>
93     ForceType text/x-cross-domain-policy
94   </Files>
95
96   #
97   # Set expiry for assets
98   #
99   <Location /assets/>
100     Header unset Last-Modified
101     FileETag Size
102
103     ExpiresDefault "access plus 1 year"
104     Header set Cache-Control "immutable, max-age=31536000"
105   </Location>
106
107   #
108   # Set expiry for attachments
109   #
110   <Location /attachments/>
111     Header unset ETag
112     FileETag None
113
114     ExpiresDefault "access plus 1 year"
115   </Location>
116
117   #
118   # Set expiry for other static content
119   #
120   <Location /export/embed.html>
121     ExpiresDefault "access plus 7 days"
122   </Location>
123   <Location /images/>
124     ExpiresDefault "access plus 10 years"
125   </Location>
126   <Location /openlayers/>
127     Header unset Last-Modified
128     FileETag Size
129
130     Header always set Cache-Control "public, max-age=31536000, immutable"
131     Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
132   </Location>
133
134   #
135   # Configure rails
136   #
137   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
138   RailsEnv production
139   PassengerMinInstances 10
140   PassengerMaxRequests 5000
141   PassengerMaxRequestQueueSize 250
142   PassengerPreStart https://www.openstreetmap.org/
143   PassengerAppGroupName rails
144   SetEnv OPENSTREETMAP_STATUS <%= @status %>
145   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
146   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
147   Alias /openlayers <%= node[:web][:base_directory] %>/static/openlayers
148   RedirectPermanent /stats https://planet.openstreetmap.org/statistics
149
150   #
151   # Pass authentication related headers to cgimap
152   #
153   <Location />
154     CGIPassAuth On
155   </Location>
156
157   #
158   # Pass supported calls to cgimap
159   #
160   RewriteRule ^/api/0\.6/map(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
161   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
162   RewriteRule ^/api/0\.6/(node|way|relation|changeset)/[0-9]+(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
163   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/history(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
164   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/relations(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
165   RewriteRule ^/api/0\.6/node/[0-9]+/ways(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
166   RewriteRule ^/api/0\.6/(way|relation)/[0-9]+/full(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
167   RewriteRule ^/api/0\.6/(nodes|ways|relations)(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
168   RewriteRule ^/api/0\.6/changeset/[0-9]+/(upload|download)(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
169
170   #
171   # Redirect trac and wiki requests to the right places
172   #
173   RedirectPermanent /trac/ https://trac.openstreetmap.org/
174   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
175
176   #
177   # Redirect requests for various images to the right place
178   #
179   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
180   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
181
182   #
183   # Redirect api requests made to www.openstreetmap.org to api.openstreetmap.org
184   #
185 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
186 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
187
188   #
189   # Redirect non-api requests made to api.openstreetmap.org to www.openstreetmap.org
190   #
191   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
192   RewriteCond %{REQUEST_URI} !^/api/
193   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
194 </VirtualHost>
195
196 <VirtualHost *:80>
197   ServerName openstreetmap.org.uk
198   ServerAlias www.openstreetmap.org.uk
199   ServerAlias openstreetmap.co.uk
200   ServerAlias www.openstreetmap.co.uk
201
202   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
203   RedirectPermanent / https://www.openstreetmap.org/
204 </VirtualHost>
205
206 <VirtualHost *:80>
207   ServerName osm.org
208
209   Header always set Cache-Control "max-age=31536000"
210   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
211
212   RewriteEngine on
213
214   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
215
216   RewriteCond %{REQUEST_URI} !^/server-status$
217   RewriteRule ^(.*)$ https://osm.org$1 [L,NE,R=permanent]
218 </VirtualHost>
219
220 <VirtualHost *:80>
221   ServerName www.osm.org
222
223   Header always set Cache-Control "max-age=31536000"
224   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
225
226   RewriteEngine on
227
228   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
229
230   RewriteCond %{REQUEST_URI} !^/server-status$
231   RewriteRule ^(.*)$ https://www.osm.org$1 [L,NE,R=permanent]
232 </VirtualHost>
233
234 <VirtualHost *:80>
235   ServerName openstreetmap.org
236
237   Header always set Cache-Control "max-age=31536000"
238   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
239
240   RewriteEngine on
241
242   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
243
244   RewriteCond %{REQUEST_URI} !^/server-status$
245   RewriteRule ^(.*)$ https://openstreetmap.org$1 [L,NE,R=permanent]
246 </VirtualHost>
247
248 <VirtualHost *:80>
249   ServerName www.openstreetmap.org
250   ServerAlias *
251
252   Header always set Cache-Control "max-age=31536000"
253   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
254
255   RewriteEngine on
256
257   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
258
259   RewriteCond %{REQUEST_URI} !^/server-status$
260   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
261 </VirtualHost>
262
263 <VirtualHost *:443>
264   ServerName openstreetmap.org
265   ServerAlias *
266
267   SSLEngine on
268   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
269   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
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   RedirectPermanent / https://www.openstreetmap.org/
275 </VirtualHost>
276
277 <Directory <%= node[:web][:base_directory] %>/rails/public>
278   Require all granted
279
280   RewriteCond "%{HTTP:Accept-encoding}" "br"
281   RewriteCond "%{REQUEST_FILENAME}\.br" -s
282   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.br" [QSA]
283
284   RewriteCond "%{HTTP:Accept-encoding}" "gzip"
285   RewriteCond "%{REQUEST_FILENAME}\.gz" -s
286   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.gz" [QSA]
287
288   RewriteRule "\.css\.(br|gz)$" "-" [T=text/css,E=no-gzip:1,E=no-brotli:1]
289   RewriteRule "\.ico\.(br|gz)$"  "-" [T=image/vnd.microsoft.icon,E=no-gzip:1,E=no-brotli:1]
290   RewriteRule "\.js\.(br|gz)$"  "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
291   RewriteRule "\.json\.(br|gz)$"  "-" [T=application/json,E=no-gzip:1,E=no-brotli:1]
292   RewriteRule "\.svg\.(br|gz)$"  "-" [T=image/svg+xml,E=no-gzip:1,E=no-brotli:1]
293   RewriteRule "\.xml\.(br|gz)$"  "-" [T=application/xml,E=no-gzip:1,E=no-brotli:1]
294
295   <FilesMatch "\.(css|ico|js|json|svg|xml)\.br$">
296     Header append Content-Encoding br
297     Header append Vary Accept-Encoding
298   </FilesMatch>
299
300   <FilesMatch "\.(css|ico|js|json|svg|xml)\.gz$">
301     Header append Content-Encoding gzip
302     Header append Vary Accept-Encoding
303   </FilesMatch>
304 </Directory>
305
306 <Directory /srv/www.openstreetmap.org/static>
307   Require all granted
308 </Directory>
309
310 <Directory /srv/www.openstreetmap.org/rails/app/assets>
311   Require all granted
312 </Directory>
313
314 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
315   Require all granted
316 </Directory>