]> git.openstreetmap.org Git - chef.git/blob - cookbooks/web/templates/default/apache.frontend.erb
Merge remote-tracking branch 'tigerfell/pr257'
[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:WWW-Authenticate} =~ /^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   # 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 attempts to access old API versions
62   #
63   RewriteRule ^/api/0.[12345]/ - [G,L]
64
65   #
66   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
67   # lat/lon to be swapped (https://josm.openstreetmap.de/ticket/2804)
68   #
69   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
70   RewriteRule . - [F,L]
71
72   #
73   # Block a changeset that seems to lock things up
74   #
75   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
76
77   #
78   # Ignore Vicon Valerus "online" status pings
79   # https://gist.github.com/Firefishy/86ed5b86991b225179b54bbafbcd769e
80   #
81   RewriteCond "%{QUERY_STRING}" "^q=abcde&t=20"
82   RewriteRule "^/api/0\.6/notes/search$" - [R=429,L]
83
84   #
85   # Force special MIME type for crossdomain.xml files
86   #
87   <Files crossdomain.xml>
88     ForceType text/x-cross-domain-policy
89   </Files>
90
91   #
92   # Set expiry for assets
93   #
94   <Location /assets/>
95     Header unset Last-Modified
96     FileETag Size
97
98     ExpiresDefault "access plus 1 year"
99     Header set Cache-Control "immutable, max-age=31536000"
100   </Location>
101
102   #
103   # Set expiry for attachments
104   #
105   <Location /attachments/>
106     Header unset ETag
107     FileETag None
108
109     ExpiresDefault "access plus 1 year"
110   </Location>
111
112   #
113   # Set expiry for other static content
114   #
115   <Location /export/embed.html>
116     ExpiresDefault "access plus 7 days"
117   </Location>
118   <Location /images/>
119     ExpiresDefault "access plus 10 years"
120   </Location>
121   <Location /openlayers/>
122     Header unset Last-Modified
123     FileETag Size
124
125     Header always set Cache-Control "public, max-age=31536000, immutable"
126     Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
127   </Location>
128
129   #
130   # Configure rails
131   #
132   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
133   RailsEnv production
134   PassengerMinInstances 10
135   PassengerMaxRequests 5000
136   PassengerMaxRequestQueueSize 250
137   PassengerPreStart https://www.openstreetmap.org/
138   PassengerAppGroupName rails
139   SetEnv OPENSTREETMAP_STATUS <%= @status %>
140   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
141   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
142   Alias /openlayers <%= node[:web][:base_directory] %>/static/openlayers
143   RedirectPermanent /stats https://planet.openstreetmap.org/statistics
144
145   #
146   # Pass authentication related headers to cgimap
147   #
148   <Location />
149     CGIPassAuth On
150   </Location>
151
152   #
153   # Pass supported calls to cgimap
154   #
155   RewriteRule ^/api/0\.6/map(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
156   RewriteCond %{REQUEST_METHOD} ^(HEAD|GET)$
157   RewriteRule ^/api/0\.6/(node|way|relation|changeset)/[0-9]+(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
158   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/history(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
159   RewriteRule ^/api/0\.6/(node|way|relation)/[0-9]+/relations(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
160   RewriteRule ^/api/0\.6/node/[0-9]+/ways(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
161   RewriteRule ^/api/0\.6/(way|relation)/[0-9]+/full(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
162   RewriteRule ^/api/0\.6/(nodes|ways|relations)(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
163   RewriteRule ^/api/0\.6/changeset/[0-9]+/(upload|download)(\.json|\.xml)?$ fcgi://127.0.0.1:8000$0 [P]
164
165   #
166   # Redirect trac and wiki requests to the right places
167   #
168   RedirectPermanent /trac/ https://trac.openstreetmap.org/
169   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
170
171   #
172   # Redirect requests for various images to the right place
173   #
174   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
175   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
176
177   #
178   # Redirect api requests made to www.openstreetmap.org to api.openstreetmap.org
179   #
180 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
181 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
182
183   #
184   # Redirect non-api requests made to api.openstreetmap.org to www.openstreetmap.org
185   #
186   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
187   RewriteCond %{REQUEST_URI} !^/api/
188   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
189 </VirtualHost>
190
191 <VirtualHost *:80>
192   ServerName openstreetmap.org.uk
193   ServerAlias www.openstreetmap.org.uk
194   ServerAlias openstreetmap.co.uk
195   ServerAlias www.openstreetmap.co.uk
196
197   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
198   RedirectPermanent / https://www.openstreetmap.org/
199 </VirtualHost>
200
201 <VirtualHost *:80>
202   ServerName osm.org
203
204   Header always set Cache-Control "max-age=31536000"
205   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
206
207   RewriteEngine on
208
209   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
210
211   RewriteCond %{REQUEST_URI} !^/server-status$
212   RewriteRule ^(.*)$ https://osm.org$1 [L,NE,R=permanent]
213 </VirtualHost>
214
215 <VirtualHost *:80>
216   ServerName www.osm.org
217
218   Header always set Cache-Control "max-age=31536000"
219   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
220
221   RewriteEngine on
222
223   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
224
225   RewriteCond %{REQUEST_URI} !^/server-status$
226   RewriteRule ^(.*)$ https://www.osm.org$1 [L,NE,R=permanent]
227 </VirtualHost>
228
229 <VirtualHost *:80>
230   ServerName openstreetmap.org
231
232   Header always set Cache-Control "max-age=31536000"
233   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
234
235   RewriteEngine on
236
237   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
238
239   RewriteCond %{REQUEST_URI} !^/server-status$
240   RewriteRule ^(.*)$ https://openstreetmap.org$1 [L,NE,R=permanent]
241 </VirtualHost>
242
243 <VirtualHost *:80>
244   ServerName www.openstreetmap.org
245   ServerAlias *
246
247   Header always set Cache-Control "max-age=31536000"
248   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
249
250   RewriteEngine on
251
252   RewriteRule ^/\.well-known/acme-challenge/(.*)$ http://acme.openstreetmap.org/.well-known/acme-challenge/$1 [R=permanent,L]
253
254   RewriteCond %{REQUEST_URI} !^/server-status$
255   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
256 </VirtualHost>
257
258 <VirtualHost *:443>
259   ServerName openstreetmap.org
260   ServerAlias *
261
262   SSLEngine on
263   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
264   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
265
266   Header always set Cache-Control "max-age=31536000"
267   Header always set Expires "Tue, 19 Jan 2038 03:14:07 GMT"
268
269   RedirectPermanent / https://www.openstreetmap.org/
270 </VirtualHost>
271
272 <Directory <%= node[:web][:base_directory] %>/rails/public>
273   Require all granted
274
275   RewriteCond "%{HTTP:Accept-encoding}" "br"
276   RewriteCond "%{REQUEST_FILENAME}\.br" -s
277   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.br" [QSA]
278
279   RewriteCond "%{HTTP:Accept-encoding}" "gzip"
280   RewriteCond "%{REQUEST_FILENAME}\.gz" -s
281   RewriteRule "^(.*)\.(css|ico|js|json|svg|xml)$" "$1\.$2\.gz" [QSA]
282
283   RewriteRule "\.css\.(br|gz)$" "-" [T=text/css,E=no-gzip:1,E=no-brotli:1]
284   RewriteRule "\.ico\.(br|gz)$"  "-" [T=image/vnd.microsoft.icon,E=no-gzip:1,E=no-brotli:1]
285   RewriteRule "\.js\.(br|gz)$"  "-" [T=text/javascript,E=no-gzip:1,E=no-brotli:1]
286   RewriteRule "\.json\.(br|gz)$"  "-" [T=application/json,E=no-gzip:1,E=no-brotli:1]
287   RewriteRule "\.svg\.(br|gz)$"  "-" [T=image/svg+xml,E=no-gzip:1,E=no-brotli:1]
288   RewriteRule "\.xml\.(br|gz)$"  "-" [T=application/xml,E=no-gzip:1,E=no-brotli:1]
289
290   <FilesMatch "\.(css|ico|js|json|svg|xml)\.br$">
291     Header append Content-Encoding br
292     Header append Vary Accept-Encoding
293   </FilesMatch>
294
295   <FilesMatch "\.(css|ico|js|json|svg|xml)\.gz$">
296     Header append Content-Encoding gzip
297     Header append Vary Accept-Encoding
298   </FilesMatch>
299 </Directory>
300
301 <Directory /srv/www.openstreetmap.org/static>
302   Require all granted
303 </Directory>
304
305 <Directory /srv/www.openstreetmap.org/rails/app/assets>
306   Require all granted
307 </Directory>
308
309 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
310   Require all granted
311 </Directory>