OSRM-Backend and Nginx Proxies

I am using Nextcloud for contacts, calendar, files and so on. Nextcloud has a lot of cool Apps, a Calendar, Mail-Client, Todo-Lists, Music player… It also features a Map to show contact and image locations. The Map tiles are based on OpenStreetMap.

The Nextcloud Maps App also works with a private tile server if the public available ones are not reliable (or the cloud should not rely on third party services). To get Routing inside your Nextcloud Instance, you need to connect it to an instance of one of the compatible services:

  • GraphHopper
  • OSRM
  • Mapbox

I found out that OSRM is the only FOSS self-hosting solution here, so I am sticking with it. This Post is about setting up OSRM in a docker-container and managing it with docker-compose.

Download the navigation data from Geofabrik

To download your routing data, we need to use https://download.geofabrik.de/

For example wget http://download.geofabrik.de/europe/germany/berlin-latest.osm.pbf

Setting the OSRM-Backend up

Reference: https://hub.docker.com/r/osrm/osrm-backend

And: https://afi.io/blog/introduction-to-osrm-setting-up-osrm-backend-using-docker/

Stopping the project.

While the OSRM solution is very good for an offline map service it is also very resource intensive - the data needs more than 10GB for maps as well as a lot of calculation time to generate the routing as preprocessing. I decided to stop using it, as I can far better directly use OpenStreetMaps.org

Switching to Nginx instead

It is much less waste of space to just relay requests to OpenStreetMaps.org and cache the typical required subset on the server in a temporal directory. This ensures, that user privacy is still given without forwarding client information to openstreetmap, and it reduces load on the openstreetmap side as well.

This is entirely possible using Nginx with configurations like these:

To do this in a temp folder, one has to create the temp directory on every boot:

sudo mkdir -p /tmp/tilecache
sudo chown -R www-data:www-data /tmp/tilecache

Which can also be set up using systemd-tmpfiles by creating a file /etc/tmpfiles.d/tilecache with this content:

d /tmp/tilecache/ 1744 www-data www-data

Yet, this only works for tiles, but not for routing information. If you need these too, you have to stick to OSRM though.