Hi everyone,
I recently rebuilt my Home Assistant server and encountered a frustrating 502 Bad Gateway error. After some digging, I found the solution and thought I’d share it in case anyone else runs into the same issue.
The problem occurred after setting up Docker and Swag (Secure Web Application Gateway) for SSL termination. I noticed that accessing Home Assistant through the subdomain resulted in the 502 error. After checking the logs and configuration files, I realized the issue was with how the proxy was set up.
Here’s what I did to fix it:
-
Edit the Configuration File: I located the
homeassistant.subdomain.conffile in my Swag configuration directory. This file handles the proxy settings for Home Assistant. -
Modify the Proxy Pass: The original configuration was using
proxy_pass http://localhost:8123;, which wasn’t working. I changed it to use the server’s local IP address instead. For example, if my server’s IP is192.168.1.100, I updated the line toproxy_pass http://192.168.1.100:8123;. -
Reload Swag Configuration: After making the changes, I reloaded the Swag configuration to apply the new settings. This can usually be done through the Docker interface or by restarting the Swag container.
-
Test the Connection: I accessed my Home Assistant instance again through the subdomain, and the 502 error was resolved. Everything worked as expected!
Why This Worked: Using the server’s local IP address ensures that the proxy correctly routes traffic to the Home Assistant container. The initial setup with localhost might not work because Docker containers might not resolve localhost correctly when dealing with external requests.
Tips for Others:
- Always check your proxy configuration when setting up SSL termination with Swag.
- If you’re using Docker, make sure your containers are on the same Docker network for proper communication.
- Don’t hesitate to look at your server logs if you encounter issues. They often provide valuable clues about what’s going wrong.
I hope this helps someone else who’s struggling with the same issue. It was a bit of a headache, but solving it gave me a great sense of accomplishment!
Best regards,
[Your Name]