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