Configuration HASS behind Nginx with a custom baseurl

Hi all-

I’m relatively new to HASS but I’m over the moon having found it. I’m trying to get HASS set up behind Nginx, but it seems that all of the documentation I’ve found expects the external URL to be at a subdomain (i.e. “ha.myurl.com”), whereas my existing Nginx configuration uses subdirectories (i.e. “myurl.com/ha”). I’ve got the basic redirect working, but all I get is the main logo. Chrome DevTools shows a litany loading errors where it’s clear that HA is attempting to load its resources from the root dir instead of “/ha”:

The resource https://myurl.com/static/fonts/roboto/Roboto-Medium.woff2 was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate `as` value and it is preloaded intentionally.

I see that there used to be “base_url” /“external_url” / “internal_url” properties within configuration.yaml, but I get config errors when attempting to set those. What’s the proper way to set up HA to expect requests at “myUrl/ha” instead of “myUrl”?

HA doesn’t support being accessed via a path like that. It has to be hosted on a subdomain.

Fair enough. Set up a subdomain for this, and now I’m seeing this non-specific error:

The logs show:

Logger: aiohttp.server
Source: /usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py:405
First occurred: 6:05:23 PM (5 occurrences)
Last logged: 6:05:29 PM

Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 514, in start
    resp, reset = await task
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 460, in _handle_request
    reset = await self.finish_response(request, resp, start_time)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 599, in finish_response
    self._request_parser.feed_data(self._message_tail)
  File "aiohttp/_http_parser.pyx", line 551, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message="Bad status line 'Invalid method encountered'"

the nginx error log says:

2022/06/06 21:05:29 [error] 62486#101757: *2168 upstream prematurely closed connection while reading response header from upstream, client: 10.0.1.1, server: xx.xxx.xxx, request: "POST /auth/login_flow HTTP/1.1", upstream: "http://10.0.1.225:8123/auth/login_flow", host: "xx.xxx.xxx", referrer: "https://xx.xxx.xxx/auth/authorize?response_type=code&redirect_uri=https%3A%2F%2Fxx.xxx.xxx%2F%3Fauth_callback%3D1&client_id=https%3A%2F%2Fxx.xxx.xxx%2F&state=eyJoYXNzVXJsIjoiaHR0cHM6Ly9oYS5kampkLnVzIiwiY2xpZW50SWQiOiJodHRwczovL2hhLmRqamQudXMvIn0%3D"

and in configuration.yaml I have the following, where 10.0.1.220 is the LAN address of my nginx server:

http:

  # https://www.home-assistant.io/integrations/http/#ip_ban_enabled
  ip_ban_enabled: False
  login_attempts_threshold: 5
  use_x_forwarded_for: true
  trusted_proxies: 10.0.1.220

Not sure what I missed here…

Solved it - nginx really wanted the “map” declaration for $http_upgrade and $connection_upgrade. Replaced those and that now works. Yay!