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)


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


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


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”, “” 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:

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:

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’
image: linuxserver/letsencrypt
container_name: letsencrypt
- PUID=1000
- PGID=1000
- TZ=Europe/Stockholm
- SUBDOMAINS=wildcard
- VALIDATION=duckdns
- DHLEVEL=2048 #optional
- ./letsencrypt_config:/config
- 443:443
- 80:80 #optional
restart: unless-stopped
- pihole
- homeassistant

container_name: pihole
image: pihole/pihole:latest
- TZ=Europe/Stockholm
- ServerIP=192.168.1.YYY
- /home/erik/pihole_config/etc-pihole/:/etc/pihole/
- /home/erik/pihole_config/etc-dnsmasq.d/:/etc/dnsmasq.d/
restart: unless-stopped

image: homeassistant/home-assistant
container_name: homeassistant
- PUID=1000
- PGID=1000
- TZ=Europe/Stockholm
- /home/erik/HomeAssistant_config:/config
- /etc/localtime:/etc/localtime:ro
- /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.