1 # DO NOT EDIT - This file is being maintained by Chef
 
   3 <% [80, 443].each do |port| -%>
 
   4 <VirtualHost *:<%= port %>>
 
   6   # Basic server configuration
 
   8   ServerName <%= node[:fqdn] %>
 
   9   ServerAlias api.openstreetmap.org www.openstreetmap.org 127.0.0.1
 
  10   ServerAdmin webmaster@openstreetmap.org
 
  18   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
 
  19   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
 
  22   # Disable HSTS for Firefox 52 to avoid issues with remote editing
 
  24   BrowserMatch Firefox/52 no-hsts
 
  25   Header set Strict-Transport-Security "max-age=0" env=no-hsts
 
  31   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
 
  32   CustomLog /var/log/apache2/access.log combined_with_time
 
  33   ErrorLog /var/log/apache2/error.log
 
  36   # Turn on various features
 
  42   # Add the unique ID to the request headers
 
  44   RequestHeader set X-Request-Id %{UNIQUE_ID}e
 
  47   # Remove Proxy request header to mitigate https://httpoxy.org/
 
  49   RequestHeader unset Proxy early
 
  52   # Block troublesome GPX data scrapping
 
  54   RewriteCond %{REQUEST_METHOD} HEAD
 
  55   RewriteRule ^/trace/\d+/data - [F,L]
 
  60   RewriteCond %{HTTP_USER_AGENT} tilesAtHome
 
  64   # Block changeset scraper
 
  66   RewriteCond %{HTTP_USER_AGENT} "OSMApp Tuner"
 
  70   # Block requests for the old 404 map tile
 
  72   RewriteRule ^/openlayers/img/404.png$ - [G,L]
 
  75   # Block attempts to access old API versions
 
  77   RewriteRule ^/api/0.[12345]/ - [G,L]
 
  80   # Block JOSM revisions  1722-1727 as they have a serious bug that causes
 
  81   # lat/lon to be swapped (https://josm.openstreetmap.de/ticket/2804)
 
  83   RewriteCond %{HTTP_USER_AGENT} "^JOSM/[0-9]+\.[0-9]+ \(172[234567]\)"
 
  87   # Block a changeset that seems to lock things up
 
  89   RewriteRule ^/api/0.6/changeset/6823497/download$ - [F,L]
 
  92   # Force special MIME type for crossdomain.xml files
 
  94   <Files crossdomain.xml>
 
  95     ForceType text/x-cross-domain-policy
 
  99   # Set expiry for assets
 
 102     Header unset Last-Modified
 
 106     ExpiresDefault "access plus 1 year"
 
 110   # Set expiry for attachments
 
 112   <Location /attachments/>
 
 113     Header unset Last-Modified
 
 117     ExpiresDefault "access plus 1 year"
 
 121   # Set expiry for other static content
 
 123   <Location /export/embed.html>
 
 124     ExpiresDefault "access plus 7 days"
 
 127     ExpiresDefault "access plus 10 years"
 
 129   <Location /javascripts/>
 
 130     ExpiresDefault "access plus 10 years"
 
 132   <Location /openlayers/>
 
 133     ExpiresDefault "access plus 7 days"
 
 135   <Location /stylesheets/>
 
 136     ExpiresDefault "access plus 10 years"
 
 140   # Set expiry for Potlatch 1
 
 142   <Location /potlatch/>
 
 143     ExpiresDefault "access plus 7 days"
 
 147   # Set expiry for Potlatch 2
 
 149   <Location /potlatch2/>
 
 150     ExpiresByType application/x-shockwave-flash "access plus 1 day"
 
 151     ExpiresByType application/xml "access plus 1 day"
 
 152     ExpiresByType text/css "access plus 1 day"
 
 153     ExpiresByType image/png "access plus 7 days"
 
 159   DocumentRoot <%= node[:web][:base_directory] %>/rails/public
 
 161   PassengerMinInstances 10
 
 162   PassengerMaxRequests 5000
 
 163   PassengerMaxRequestQueueSize 250
 
 164 <% if port == 443 -%>
 
 165   PassengerPreStart https://www.openstreetmap.org/
 
 167   PassengerPreStart http://www.openstreetmap.org/
 
 169   SetEnv SECRET_KEY_BASE <%= @secret_key_base %>
 
 170   Alias /favicon.ico <%= node[:web][:base_directory] %>/rails/app/assets/favicons/favicon.ico
 
 171   Alias /openlayers <%= node[:web][:base_directory] %>/rails/vendor/assets/openlayers
 
 172   Alias /stats /store/rails/stats
 
 173   Alias /user/image /store/rails/user/image
 
 174   Alias /attachments /store/rails/attachments
 
 177   # Preserve the host name when forwarding to the proxy
 
 182   # Set a long timeout - changeset uploads can take a long time
 
 187   # Allow all proxy requests
 
 194   # Pass some other API calls to the backends via a load balancer
 
 196   ProxyPass /api/0.6/map balancer://backend/api/0.6/map
 
 197   ProxyPass /api/0.6/tracepoints balancer://backend/api/0.6/tracepoints
 
 198   ProxyPass /api/0.6/amf/read balancer://backend/api/0.6/amf/read
 
 199   ProxyPass /api/0.6/swf/trackpoints balancer://backend/api/0.6/swf/trackpoints
 
 200   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+)$ balancer://backend$1
 
 201   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/upload)$ balancer://ic$1
 
 202   ProxyPassMatch ^(/api/0\.6/changeset/[0-9]+/download)$ balancer://backend$1
 
 203   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+)$ balancer://backend$1
 
 204   ProxyPassMatch ^(/api/0\.6/(node|way|relation)/[0-9]+/(full|history|search|ways))$ balancer://backend$1
 
 205   ProxyPass /api/0.6/nodes balancer://backend/api/0.6/nodes
 
 206   ProxyPass /api/0.6/ways balancer://backend/api/0.6/ways
 
 207   ProxyPass /api/0.6/relations balancer://backend/api/0.6/relations
 
 208   ProxyPassMatch ^(/trace/[0-9]+/data(|/|.xml))$ balancer://backend$1
 
 211   # Redirect ACME certificate challenges
 
 213   RedirectPermanent /.well-known/acme-challenge/ http://acme.openstreetmap.org/.well-known/acme-challenge/
 
 216   # Redirect trac and wiki requests to the right places
 
 218   RedirectPermanent /trac/ https://trac.openstreetmap.org/
 
 219   RedirectPermanent /wiki/ https://wiki.openstreetmap.org/
 
 222   # Redirect requests for various images to the right place
 
 224   RedirectPermanent /images/osm_logo.png https://www.openstreetmap.org/assets/osm_logo.png
 
 225   RedirectPermanent /images/cc_button.png https://www.openstreetmap.org/assets/cc_button.png
 
 228   # Define a load balancer for the local backends
 
 230   <Proxy balancer://backend>
 
 231     ProxySet lbmethod=bybusyness
 
 232 <% node[:web][:backends].each do |backend| -%>
 
 233 <% if port == 443 -%>
 
 234     BalancerMember https://<%= backend %> disablereuse=on
 
 236     BalancerMember http://<%= backend %>
 
 242   # Define a load balancer for the IC backends
 
 244   <Proxy balancer://ic>
 
 245     ProxySet lbmethod=bybusyness
 
 246 <% ["rails1.ic", "rails2.ic", "rails3.ic"].each do |backend| -%>
 
 247 <% if port == 443 -%>
 
 248     BalancerMember https://<%= backend %> disablereuse=on
 
 250     BalancerMember http://<%= backend %>
 
 257   # Redirect requests which should be secure to https
 
 259   RewriteCond %{REQUEST_URI} ^/login(\.html)?$ [OR]
 
 260   RewriteCond %{REQUEST_URI} ^/user/(new|create-account\.html)$ [OR]
 
 261   RewriteCond %{REQUEST_URI} ^/user/terms$ [OR]
 
 262   RewriteCond %{REQUEST_URI} ^/user/save$ [OR]
 
 263   RewriteCond %{REQUEST_URI} ^/user/([^/]+)/account$ [OR]
 
 264   RewriteCond %{REQUEST_URI} ^/user/reset-password$
 
 265   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
 
 268   # Redirect api requests made to www.osm.org to api.osm.org
 
 270 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
 
 271 #  RewriteRule ^/api/(.*)$ http://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
 
 274   # Redirect non-api requests made to api.osm.org to www.osm.org
 
 276   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
 
 277   RewriteCond %{REQUEST_URI} !^/api/
 
 278   RewriteRule ^(.*)$ http://www.openstreetmap.org$1 [L,NE,R=permanent]
 
 279 <% elsif port == 443 -%>
 
 282   # Redirect api requests made to www.osm.org to api.osm.org
 
 284 #  RewriteCond %{HTTP_HOST} =www.openstreetmap.org
 
 285 #  RewriteRule ^/api/(.*)$ https://api.openstreetmap.org/api/$1 [L,NE,R=permanent]
 
 288   # Redirect non-api requests made to api.osm.org to www.osm.org
 
 290   RewriteCond %{HTTP_HOST} =api.openstreetmap.org
 
 291   RewriteCond %{REQUEST_URI} !^/api/
 
 292   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
 
 298   ServerName openstreetmap.org.uk
 
 299   ServerAlias www.openstreetmap.org.uk
 
 300   ServerAlias openstreetmap.co.uk
 
 301   ServerAlias www.openstreetmap.co.uk
 
 303   RedirectPermanent /events.ics http://calendar.openstreetmap.org.uk/events.ics
 
 304   RedirectPermanent / https://www.openstreetmap.org/
 
 308   ServerName openstreetmap.org
 
 313   RewriteCond %{REQUEST_URI} !^/server-status$
 
 314   RewriteRule ^(.*)$ https://www.openstreetmap.org$1 [L,NE,R=permanent]
 
 318   ServerName openstreetmap.org
 
 322   SSLCertificateFile /etc/ssl/certs/www.openstreetmap.org.pem
 
 323   SSLCertificateKeyFile /etc/ssl/private/www.openstreetmap.org.key
 
 325   RedirectPermanent / https://www.openstreetmap.org/
 
 328 <Directory <%= node[:web][:base_directory] %>/rails/public>
 
 332 <Directory /srv/www.openstreetmap.org/rails/app/assets>
 
 336 <Directory /srv/www.openstreetmap.org/rails/vendor/assets>
 
 340 <Directory /store/rails/stats>
 
 344 <Directory /store/rails/user/image>
 
 348 <Directory /store/rails/attachments>