I could also use some assistance with this.
Summary
I use a Raspberry Pi as a reverse proxy on my home network. I would like to be able to go to https://ha.MyURL1.com
and access my Home Assistant dashboard. However, when I try, I get a Home Assistant page that reads “Unable to connect to Home Assistant,” and my NGINX error log shows several errors, mostly reading “connect() failed (111: Connection refused) while connecting to upstream”.
Details
On my network, I have one Raspberry Pi acting as a reverse proxy for three separate machines, including my Home Assistant (running on an ODROID-N2+). I’ve used the “Virtual Servers” setting of my router to route all requests on ports 443 and 80 to the Raspberry Pi.
Here is the /etc/nginx/sites-available/ha.MyURL1.com.conf
file on the Raspberry Pi:
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
# Update this line to be your domain
server_name ha.MyURL1.com;
# Ensure these lines point to your SSL certificate and key
ssl_certificate <snip>/fullchain.pem;
ssl_certificate_key <snip>/privkey.pem;
# Use these lines instead if you created a self-signed certificate
# ssl_certificate /etc/nginx/ssl/cert.pem;
# ssl_certificate_key /etc/nginx/ssl/key.pem;
# Ensure this line points to your dhparams file
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# These shouldn't need to be changed
listen [::]:443 ssl default_server ipv6only=off; # if your nginx version is >= 1.9.5 you can also add the "http2" flag here
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains";
# ssl on; # Uncomment if you are using nginx < 1.15.0
ssl_protocols TLSv1.2;
ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
proxy_buffering off;
location / {
proxy_pass https://<HA machine's internal IP>: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;
}
}
I have added this to the end of my configuration.yaml
file for Home Assistant:
http:
# For extra security set this to only accept connections on localhost if NGINX is on the same machine
# Uncommenting this will mean that you can only reach Home Assistant using the proxy, not directly via IP from other clients.
# server_host: 127.0.0.1
use_x_forwarded_for: true
# You must set the trusted proxy IP address so that Home Assistant will properly accept connections
# Set this to your NGINX machine IP, or localhost if hosted on the same machine.
trusted_proxies: <Raspberry Pi proxy IP>
Steps to reproduce
- In a browser, go to
http://ha.MyURL1.com
, or https://ha.MyURL1.com
.
Expected results
https://ha.MyURL1.com
loads my Home Assistant dashboard.
Encountered results
The browser redirects to https://ha.MyURL1.com/lovelace
and displays a Home Assistant error which reads “Unable to connect to Home Assistant.”
When the timeout concludes, I am sent to a Cloudflare error page reporting an error 502: Bad gateway.
In my NGINX error.log
, I see several entries that correspond with the timing of the request:
[…] connect() failed (111: Connection refused) while connecting to upstream […]
Additionally, earlier in the log (but not corresponding to the latest request), I see this:
2022/10/23 11:53:24 [emerg] 492#492: bind() to [::]:443 failed (98: Address already in use)
2022/10/23 11:53:24 [emerg] 492#492: bind() to [::]:443 failed (98: Address already in use)
2022/10/23 11:53:24 [emerg] 492#492: bind() to [::]:443 failed (98: Address already in use)
2022/10/23 11:53:24 [emerg] 492#492: bind() to [::]:443 failed (98: Address already in use)
2022/10/23 11:53:24 [emerg] 492#492: bind() to [::]:443 failed (98: Address already in use)
2022/10/23 11:53:24 [emerg] 492#492: still could not bind()
Extra details
I can, of course, still access HA locally by going to http://homeassistant.local:8123
.
Could any HA/NGINX wizards help me sort this out? Thank you.