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