In a self-hosting support thread titled “CSFR Error while login behind HA Proxy,” crospa91 reports encountering a CSRF error when logging into Discourse after migrating their HA Proxy setup from pfSense to OPNsense. Despite unchanged Discourse configurations and copied HA Proxy settings, the server fails to recognize client IPs, seeing only the proxy’s IP. pfaffman suggests ensuring the X-Forwarded-For header is properly configured within the Discourse container’s nginx, referencing a meta.discourse.org thread for guidance here. crospa91 notes difficulty finding updated documentation on this. RGJ identifies the missing X-Forwarded-Proto header as the likely culprit. After adding this header, crospa91 confirms the issue is resolved, sharing a screenshot of the working configuration. neounix adds that many reverse proxy guides, including this Apache example, emphasize the necessity of X-Forwarded-Proto for Discourse to function correctly behind proxies.
Hi guys, I hope this is the right section to ask for help about this.
I recently changed the reverse proxy I have in front of the discourse server.
I have a server with several discourse installed and a reverse proxy on front that point domains to the right web server.
I’ve used HA Proxy on both setup but the difference it’s the platform, before it was installed in PFSense, and now on OPNSense.
The reverse proxy works perfectly but if I try to login I get the CSFR error and can’t really do anything.
nothing have changed in the discourse setup and the HA Proxy configuration is copied over so should be fine.
I’ve turned on XforwardFor and SSL but still discourse don’t seems to keep the same IP from the client but sees only the one from the proxy.
I don’t know if it’ll fix the csfr problem (which I think has to do with https certificate problems, but don’t really know), but the forwarded for boot your did by telling the nginx inside the container what addresses to trust. You can search here for X-forwarded-for and find examples of how to fix that.
FWIW, there are many example configurations for reverse proxy servers in front of the Discourse app, including this one, almost all address “X-Forwarded-Proto”: