Proxy fails if "to" argument is a domain in /etc/hosts (502 Bad Gateway)

Hi there,

I have spent the last two days trying to figure out how to host a static html page behind a Laravel server that checks the access rights of users against an LDAP system. Long story short, I concluded that a reverse proxy would be way to go. However, as described in the link below, I have failed to get it to work :confused:

Does anyone have an idea how to fix this?

https://github.com/mholt/caddy/issues/2429#issue-399085009

Looking over it, and taking the error message into account, I’d have to guess that your public IP address is not accepting connections from itself on port 80.

I’d look into why that’s happening. I notice that every other site you’re hosting is HTTPS-only, is port 80 open externally?

The post title implies that the cause of the issue is the fact that you’re using /etc/hosts for resolution. But I don’t think that’s likely (you mention that the error message has your public IP, implying that the resolution worked just fine). You can rule out /etc/hosts resolution as the cause by replacing the domain name with your public IP address directly in the Caddyfile. If it still fails when you supply the IP explicitly for the proxy upstream target, you’ll know it’s impossible for /etc/hosts to be at fault.

If you’re having Caddy proxy to itself for these docs, why not simply proxy to itself on another port (some arbitrarily large port number?) and use internal to doubly ensure it can’t ever be accessed outside of Caddy itself? Or just host it on the domain you want to have it available on directly?

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