I recently decided to pull a server out of line, which was running an instance of Immich. Immich was only serving one purpose – providing photos from an album as the screen saver for a couple of Home Assistant dashboards around the house. Due to this removal, I needed to establish a new Immich instance to continue running the dashboard albums, which act as digital photo frames when not in use.

I installed Immich as an Add-On directly to my Home Assistant server, added an entry for Immich to the NGINX Proxy Manager (also an Add-On on my HA server) and updated the dashboards to use the correct Immich API key.

However, all was not well as I forgot that Immich required some additional configuration within NGINX due to CORS restrictions. Without it, HA can’t pull and display photos on the dashboards.

This required setting up a Custom Location in the NGINX entry for the Immich host. With my setup, the location is /. If you’re not very familiar with NGINX, as I am not, this part can be a little confusing. Since I’m using the web admin interface to configure NGINX hosts, and not directly editing config files via text editor, many of the examples one may find are not quite correct for this method of administration. Those samples are often for the full host entry – not just for handling CORS.

Included below is code one can use to make Immich work with Home Assistant (specifically, the WallPanel configuration extension available via HACS) when establishing the host entry via the web administration interface. Note that this provides only the configuration information that is required to enable proper CORD support in NGINX in this scenario:

Custom Location

if ($request_method = 'OPTIONS') {
  add_header 'Access-Control-Allow-Origin' '*' always;
  add_header 'Access-Control-Allow-Methods' 'GET, PUT, POST, DELETE, OPTIONS' always;
  add_header 'Access-Control-Allow-Headers' 'X-Api-Key, User-Agent, Content-Type' always;
  add_header 'Access-Control-Max-Age' 1728000;
  add_header 'Content-Type' 'text/plain charset=UTF-8';
  add_header 'Content-Length' 0;
  return 204;
}
if ($request_method ~* '(GET|POST)') {
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Methods' 'GET, POST, PUT, DELETE, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'X-Api-Key, User-Agent, Content-Type' always;
    add_header 'Access-Control-Max-Age' 1728000;
}

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

I’m Mike

Welcome to my blog, which I have maintained for several years, off and on, to share things that I’ve learned from numerous projects and various problem solving escapades. This is my way of giving something back to the online communities that have helped me learn more about a wide variety of topics.