Help needed: nginx + home assistant

I can access all my containers as subdomains except one, homeassistant.

h t t p s / / homeassistant . XXXXXXXXXXXXX . duckdns . org gives me;

“502 Bad Gateway, nginx/1.16.1”

As there is already a provided “homeassistant.subdomain.conf.sample” I figured I don’t need to edit it, I just removed the “sample” part an started the container again.

I can’t tell if the 502 message is due to something wrong/missing in my nginx container, or if it is from the Home Assistant conatiner.

Perhaps it’s only nginx related.

The homeassistant.subdomain.conf reads;
“# make sure that your dns has a cname set for homeassistant and that your homeassistant container is not using a base url”

So, too make sure that I’m not using a buse url, I look into my “configuration.yaml” in the Home Assistant cantainer;

No matter what I edit, I still gate the 502 gateway.

Configure a default setup of Home Assistant (frontend, api, etc)

default_config:

Uncomment this if you are using SSL/TLS, running in Docker container, etc.

http:

For extra security set this to only accept connections on localhost if NGINX is on the same machine

server_host: localhost

Update this line to be your domain

base_url: XXXXXXXXXXXXX.duckdns.org

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: localhost

The trusted proxies IP address, should that be my “192.168.1.XXX”, “localhost”, “127.0.0.11” or the nginx docker container’s IP?

Sorry for this confusing post, but it reflects how I feel… :slight_smile:

Related link

Your markdown formatting is off and very difficult to read.

See here: https://github.com/linuxserver/reverse-proxy-confs/blob/master/README.md#ensure-you-have-a-custom-docker-network

Make sure your homeassistant container is named homeassistant
Then they can reach each other via their container names as dns hostnames

Here’s another article: https://blog.linuxserver.io/2017/10/17/using-docker-networks-for-better-inter-container-communication/

Thanks for helping out and sorry for the terrible formatting on my account.

My homeassistant container was actually named “home-assistant”, but even renaming and starting it again resulted in the same error.

the homeassistant and letsencrypt share the same “stack”, and the other containers that do the same can be reached… hmmm…

Post your compose yml

"version: ‘3’
services:
letsencrypt:
image: linuxserver/letsencrypt
container_name: letsencrypt
cap_add:
- NET_ADMIN
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Stockholm
- URL=XXXXXXXXXXXXXXX.duckdns.org
- SUBDOMAINS=wildcard
- VALIDATION=duckdns
- DUCKDNSTOKEN=YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY #optional
- DHLEVEL=2048 #optional
volumes:
- ./letsencrypt_config:/config
ports:
- 443:443
- 80:80 #optional
restart: unless-stopped
depends_on:
- pihole
- homeassistant

pihole:
container_name: pihole
image: pihole/pihole:latest
environment:
- TZ=Europe/Stockholm
- ServerIP=192.168.1.YYY
volumes:
- /home/erik/pihole_config/etc-pihole/:/etc/pihole/
- /home/erik/pihole_config/etc-dnsmasq.d/:/etc/dnsmasq.d/
dns:
- 127.0.0.1
- 1.1.1.1
cap_add:
- NET_ADMIN
restart: unless-stopped

homeassistant:
image: homeassistant/home-assistant
container_name: homeassistant
environment:
- PUID=1000
- PGID=1000
- TZ=Europe/Stockholm
volumes:
- /home/erik/HomeAssistant_config:/config
- /etc/localtime:/etc/localtime:ro
devices:
- /dev/ttyACM0:/dev/ttyACM0
network_mode: host
restart: always"

Pihole works, homeassistant gets the 502.

Maybe the letsencrypt container can’t resolve the home assistant container because its on the host network?

Try changing the location in the proxy-conf to localhost or ip.

Your homeassistant is not in the same user defined bridge as it is using host networking. You can change it to bridge or, modify the proxy conf to use the host ip and port. You can’t use localhost.

Thanks all. I removed the “net=host” and instead put “expose=8123”, and now it works like a charm.
Thanks everyone for this!

You are clever people, so you know that I didn’t have to user “Ports” or “expose” for 8123, that’s what nginx is for…so I removed that and it still worked fine of course.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.