There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

Follow-up: Temporary fix for Immich's shady third-party API

Context : Immich default map tile provider (which gets sent a bunch of PII every time you use the map feature) is a company that I see no reason to trust. This is a follow-up to this post, with the permanent temporary fix I came up with. I will also summarize the general opinion from the comments, as well as some interesting piece of knowledge that commenters shared.

Hacky fix

This will use Nginx proxy module to build a caching proxy in front of Open Street Map’s tileserver and to serve a custom style.json for the maps.

This works well for me, since I already proxy all my services behind a single Nginx instance. It is probably possible to achieve similar results with other reverse proxies, but this would obviously need to be adapted.

Caching proxy

Inside Nginx’s http config block (usually in /etc/nginx/nginx.conf), create a cache zone (a directory that will hold cached responses from OSM) :


<span style="color:#323232;">http {
</span><span style="color:#323232;">     # You should not need to edit existing lines in the http block, only add the line below
</span><span style="color:#323232;">    proxy_cache_path /var/cache/nginx/osm levels=1:2 keys_zone=osm:100m max_size=5g inactive=180d;
</span><span style="color:#323232;">}
</span>

You may need to manually create the /var/cache/nginx/osm directory and set its owner to Nginx’s user (typically www-data on Debian based distros).

Customize the max_size parameter to change the maximum amount of cached data you want to store on your server. The inactive parameter will cause Nginx to discard cached data that’s not been accessed in this duration (180d ~ 6months).

Then, inside the server block that serves your Immich instance, create a new location block :


<span style="color:#323232;">server {
</span><span style="color:#323232;">    listen 443 ssl;
</span><span style="color:#323232;">    server_name immich.your-domain.tld;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    # You should not need to change your existing config, only add the location block below
</span><span style="color:#323232;">
</span><span style="color:#323232;">    location /map_proxy/ {
</span><span style="color:#323232;">        proxy_pass https://tile.openstreetmap.org/;
</span><span style="color:#323232;">        proxy_cache osm;
</span><span style="color:#323232;">        proxy_cache_valid 180d;
</span><span style="color:#323232;">        proxy_ignore_headers Cache-Control Expires;
</span><span style="color:#323232;">        proxy_ssl_server_name on;
</span><span style="color:#323232;">        proxy_ssl_name tile.openstreetmap.org;
</span><span style="color:#323232;">        proxy_set_header Host tile.openstreetmap.org;
</span><span style="color:#323232;">        proxy_set_header User-Agent "Nginx Caching Tile Proxy for self-hosters";
</span><span style="color:#323232;">        proxy_set_header Cookie "";
</span><span style="color:#323232;">        proxy_set_header Referer "";
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">}
</span>

Reload Nginx (sudo systemctl reload nginx). Confirm this works by visiting https://immich.your-domain.tld/map_proxy/0/0/0.png, which should now return a world map PNG (the one from tile.openstreetmap.org/0/0/0.png )

This config ignores cache control headers from OSM and sets its own cache validity duration (proxy_cache_valid parameter). After the specified duration, the proxy will re-fetch the tiles. 6 months seem reasonable to me for the use case, and it can probably be set to a few years without it causing issues.

Besides being lighter on OSM’s servers, the caching proxy will improve privacy by only requesting tiles from upstream when loaded for the first time. This config also strips cookies and referrer before forwarding the queries to OSM, as well as set a user agent for the proxy following OSM foundation’s guidelines (according to these guidelines, you should add a contact information to this user agent)

This can probably be made to work on a different domain than the one serving your Immich instance, but this probably requires to add the appropriate headers for CORS.

Custom style.json

I came up with the following mapstyle :


<span style="color:#323232;">{
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"version"</span><span style="color:#323232;">: </span><span style="color:#0086b3;">8</span><span style="color:#323232;">,
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"name"</span><span style="color:#323232;">: "Immich Map",
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"sources"</span><span style="color:#323232;">: {
</span><span style="color:#323232;">    </span><span style="font-weight:bold;color:#183691;">"immich-map"</span><span style="color:#323232;">: {
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"type"</span><span style="color:#323232;">: "raster",
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"tileSize"</span><span style="color:#323232;">: </span><span style="color:#0086b3;">256</span><span style="color:#323232;">,
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"tiles"</span><span style="color:#323232;">: [
</span><span style="color:#323232;">        "https://immich.your-domain.tld/map_proxy/{z}/{x}/{y}.png"
</span><span style="color:#323232;">      ]
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">  },
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"sprite"</span><span style="color:#323232;">: "https://maputnik.github.io/osm-liberty/sprites/osm-liberty",
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"glyphs"</span><span style="color:#323232;">: "https://fonts.openmaptiles.org/{fontstack}/{range}.pbf",
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"layers"</span><span style="color:#323232;">: [
</span><span style="color:#323232;">    {
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"id"</span><span style="color:#323232;">: "raster-tiles",
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"type"</span><span style="color:#323232;">: "raster",
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"source"</span><span style="color:#323232;">: "immich-map",
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"minzoom"</span><span style="color:#323232;">: </span><span style="color:#0086b3;">0</span><span style="color:#323232;">,
</span><span style="color:#323232;">      </span><span style="font-weight:bold;color:#183691;">"maxzoom"</span><span style="color:#323232;">: </span><span style="color:#0086b3;">22
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">  ],
</span><span style="color:#323232;">  </span><span style="font-weight:bold;color:#183691;">"id"</span><span style="color:#323232;">: "immich-map-dark"
</span><span style="color:#323232;">}
</span>

Replace immich.your-domain.tld with your actual Immich domain, and remember the absolute path you save this at.

One last update to nginx’s config

Since Immich currently does not provide a way to manually edit style.json, we need to serve it from http(s). Add one more location block below the previous one :


<span style="color:#323232;">location /map_style.json {
</span><span style="color:#323232;">    alias /srv/immich/mapstyle.json;
</span><span style="color:#323232;">}
</span>

Replace the alias parameter with the location where you saved the json mapstyle. After reloading nginx, your json style will be available at https://immich.your-domain.tld/map_style.json

Configure Immich to use this

For this last part, follow steps 8, 9, 10 from this guide (use the link to map_style.json for both light and dark themes). After clearing the browser or app’s cache, the map should now be loaded from your caching proxy. You can confirm this by tailing Nginx’s logs while you zoom and move around the map in Immich

Summary of comments from previous post

Self-hosting a tile server is not realistic in most cases

People who have previously worked with maps seem to confirm that there are no tile server solution lightweight enough to be self hosted by hobbyists. There is maybe some hope with generating tiles on demand, but someone with deep knowledge of the file formats involved in the process should confirm this.

Some interesting links were shared, which seem to confirm this is not realistically self-hostable with the available software :

General sentiment about this issue

In all this part, I want to emphasize that while there seems to be a consensus, this is only based on the few comments from the previous post and may be biased by the fact that we’re discussing it on a non-mainstream platform. If you disagree with anything below, please comment this post and explain your point of view.

  • Nobody declared that they had noticed the requests to a third-party server before
  • A non-negligible fraction of Immich users are interested in the privacy benefits over other solutions such as Google photos. These users do not like their self-hosted services to send requests to third-party servers without warning them first
  • The fix should consist of the following :
    • Clearly document the implications of enabling the map, and any feature that sends requests to third parties
    • Disable by default features that send requests to third parties (especially if it contains any form of geolocated data)
    • Provide a way to easily change the tile provider. A select menu with a few pre-configured style.json would be nice, along with a way to manually edit style.json (or at least some of its fields) directly from the Immich config page
catloaf ,

What was shady about it?

Scipitie ,

The first link goes into amazing detail on that. In short: all your information concerning location as well as current IP and some other metadata gets send to a basically unknown company with no transparency on how that data is handled.

I highly recommend reading the first, linked post though!

Decronym Bot , (edited )

Acronyms, initialisms, abbreviations, contractions, and other phrases which expand to something larger, that I’ve seen in this thread:

Fewer Letters More Letters
DNS Domain Name Service/System
HTTP Hypertext Transfer Protocol, the Web
nginx Popular HTTP server

2 acronyms in this thread; the most compressed thread commented on today has 3 acronyms.

[Thread for this sub, first seen 24th Jul 2024, 15:15] [FAQ] [Full list] [Contact] [Source code]

just_another_person ,

Christ. If you had such a problem with it, just block the DNS or create a diff of a code fix. This is over the top lol

pcouy OP ,

Blocking the DNS was the first thing I did. This is intended to restore the map feature without having to trust a random company I’ve never heard of.

What do you mean by “a diff of a code fix” that would be simpler ?

just_another_person ,

Fix the code without forking the repo, then provide the diff if others want to apply it themselves.

pcouy OP ,

How does an nginx config fit as a “diff” when the Immich repo and docker images do not include nginx (or any other reverse proxy) ?

just_another_person , (edited )

That’s why I said fix the code…nginx is not the code.

pcouy OP , (edited )

At this point, I’ll just assume you are trolling and stop replying after this comment.

This post is trying to provide a generic solution to the fact that there are no reasonable way to get map tiles without relying on a third party provider.

I additionally included instructions on how to set it up with Immich, but I don’t see how a caching proxy in front of OSM should be part of Immich, a software focused on managing photo libraries.

Mondez ,

He’s being a dick and suggesting you fix this in immich rather than provide this stop gap workaround. I for one appreciate your diligence in pointing this out as I’d seen no mention of it prior to your first post.

paperd ,

Don’t listen to this person, this is an awesome post.

Retro_unlimited ,

Can I just block the 3rd party company URL on my router?

pcouy OP ,

You can, but you would not be able to display the map. Might as well disable the map server-wide

HybridSarcasm ,
@HybridSarcasm@lemmy.world avatar

This is good stuff. Has it been posted to the project’s GitHub (issue, discussion, etc.)?

pcouy OP ,

Not yet, but I will probably submit a PR to include this guide in the docs

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines