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