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