Sporadic "504 Gateway Timeout" errors behind Apache reverse proxy

Hi,

I’m running HA behind an Apache (2.4) reverse proxy, configured like this:

<VirtualHost xxx.xxx.xxx.xxx:443>
        ServerName 		hass.example.com
        DocumentRoot	/var/www/html
 
        SSLEngine On
        SSLCertificateFile			[...]
        SSLCertificateKeyFile		[...]
        SSLCertificateChainFile		[...]
        SSLCACertificateFile		[...]

        ProxyPass				/api/websocket  ws://localhost:8123/api/websocket
        ProxyPassReverse		/api/websocket  ws://localhost:8123/api/websocket
        ProxyPass				/				http://127.0.0.1:8123/
        ProxyPassReverse		/				http://127.0.0.1:8123/
        ProxyPreserveHost		On
        RewriteEngine			On
</VirtualHost>

Since, I think, the 0.38 release, I quite often receive “Gateway Timeout” errors from the Apache instance when trying to load the HA web interface.
The error message appears instantly, no waiting for a timeout required.
I sometimes have to reload the page 10-15 times until the Web UI finally shows up.
Once it’s loaded, everything works perfectly, i.e. I don’t get those errors when switching tabs or switching controls in the UI and states of entities are updated in the UI.

Looking at the Apache error log, I see a lot of those messages:

[proxy_http:error] [pid 11160] (104)Connection reset by peer: [client xxx.xxx.xxx.xxx:53407] AH01102: error reading status line from remote server 127.0.0.1:8123
[proxy:error] [pid 11160] [client xxx.xxx.xxx.xxx:53407] AH00898: Error reading from remote server returned by /

Does anyone have an idea what’s causing this?

Sebastian

Adding a me too to this. Since the new web interface on 0.38 I too can’t connect to HA via a reverse proxy. Local LAN connections work fine.

I’m using nginx so doesn’t seem to be web server specific. A colleague at work with the same setup also has the same problem.

I had intended to test things more before posting but not had time yet. I wanted to at least set up a temporary reverse proxy using the same settings as shown here https://home-assistant.io/docs/ecosystem/nginx/ just to demonstrate the issue was repeatable.

My entry for HA is as follows:

location / {
        proxy_pass        http://192.168.0.1:8123;
	    proxy_set_header Host $host;
        proxy_redirect http:// https://;
        proxy_http_version 1.1;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Upgrade $http_upgrade;
#	proxy_set_header Connection $connection_upgrade;
}

Me too having issues connecting to hass from outside through nginx reverse proxied to Apache. The issue is noticeable with Locative trying to connect.

Sounds i am not alone with that problem :slight_smile:, also reverse Proxy settings from here

Sometimes it works without problems but sometimes it can not connect. Same for Amazon Echo connecting to hass, sometimes it can reach hass sometimes not.

Any news here? I still have the same problem. Is that a bug and is there a ticket for that. Is the Hass team working on that problem? Or do we need to update our proxy?

I still have this problem. I have this only with HA and none of other services I reverse-proxy on this system.
I think it’s a bug, but I was hoping someone from the developers would confirm it.

Sebastian

Now there’s a bug report:

Sebastian

1 Like

Anyone still having this problem? I just started getting 504s from my nginx reverse proxy, but if I hit Pi directly, I get a response almost immediately. My setup is based on https://www.home-assistant.io/docs/ecosystem/nginx/ and https://www.home-assistant.io/docs/ecosystem/nginx_subdomain/. Any suggestions?

I still have the disablereuse=on option in my config and haven’t seen the issue since.
Maybe there’s something similar with nginx.

Sebastian