CSFR-fout bij het inloggen achter HA Proxy

AI-generated summary

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.

This the reddit post where I’ve asked support as well: Reddit - Please wait for verification

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.

Thanks for your reply.
I had a look on the forum for that but can’t really find any updated information.

there is a bunch of old topics with the reference of Real_ip to put in nginx inside the container, but I have no clue on how to do that.

do you suggest any specific guide?

I don’t see a specific guide, but I’ll try to create one soon. Here’s this Inconsistent / missing registration & last IP - #13 by pfaffman that I think should give you what you need for the real-ip bit.

You need to send an X-Forwarded-Proto header as well.

THANKS! Really I was 3 days I was running around in circles and this solved it!

I’ve added the Proto Header as well and it worked!

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