Reverse proxy (nginx) doesn't work to subdirectory

Hi all. I’m just getting started with Home Assistant and trying to integrate into my existing setup. Here are the details:

  • Ubuntu 18.04 physical server running docker
  • Running the homeassistant/home-assistant:stable container
  • Nginx reverse proxy configured on the Ubuntu server

What I’m trying to do is reverse proxy home assistant to https://mydomain.com/assistant. In my configuration.yml I have (note: my actual domain name changed to “mydomain”:

http:
    base_url: https://www.mydomain.com/assistant

My “location” block in my nginx config I have:

location /assistant/ {
        proxy_pass http://localhost:8123/;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_http_version 1.1;
    }

When I load this all up and point my browser to https://mydomain.com/assistant the page loads with just the light blue title ribbon and that’s it. If I point it to my root (i.e. https://mydomain.com, it works fine. Looking at the nginx error logs, I see this (Note: I’ve replaced my actual domain with “mydomain” and the IP address with “<ip_address>”):

2019/10/21 17:45:40 [error] 20089#20089: *2 open() "/usr/share/nginx/html/manifest.json" failed (2: No such file or
directory), client: <ip_address>, server: www.mydomain.com, request: "GET /manifest.json HTTP/1.1", host: "mydomain.com", referrer: "https://mydomain.com/lovelace"
2019/10/21 17:45:41 [error] 20089#20089: *2 open() "/usr/share/nginx/html/service_worker.js" failed (2: No such file
 or directory), client: <ip_address>, server: www.mydomain.com, request: "GET /service_worker.js HTTP/1.1", host:
 "chriskast.com", referrer: "https://mydomain.com/service_worker.js"
2019/10/21 17:45:43 [error] 20089#20089: *1 open() "/usr/share/nginx/html/lovelace" failed (2: No such file or direc
tory), client: <ip_address>, server: www.mydomain.com, request: "GET /lovelace HTTP/1.1", host: "mydomain.com", referrer: "https://mydomain.com/lovelace"

It looks like HA thinks it’s running at the root folder, hence the call to https://mydomain.com/lovelace instead of https://mydomain.com/assistant/lovelace. Am I missing some configuration here? I have 3 other https redirects to subfolders for other webapps and those work just fine.

Thanks!

This setup (path) is not supported in HA.

An alternative is to use a dedicated subdomain for proxying HA requests.

Hmm. That’s a bummer. Then why bother having a “base URL” in the config? My current SSL cert is only for a single domain and I would prefer not to have to spend more for the wildcard one. But I guess I may have to eventually.

1 Like

Why are you not using Let’s Encrypt free SSL certs?

3 Likes

According to the documentation:

Note that this setting may only contain a protocol, hostname and port; using a path is not currently supported.

1 Like

That’s a very good question. I’ve been using my CA provider for years and just didn’t think of anything else. I’ve seen people using LE…maybe it’s time I do as well. Thanks!

I really think supporting hosing ha in a reverse proxy sub directory is quite resonable and the functionality is explicitly supported by several other projects. How can i best add this as a feature request?

e.g. in Sonarr it is named:
“URL Base”

1 Like

Any alternative to this

This can be closed by a moderator. HomeAssistant knows what you need and you don’t need this! Without a Fork this will never happen!