https://community.n8n.io/t/solved-connection-lost-invalid-origin-error-with-n8n-1-87-0-behind-cloudflare-tunnel/99913/1
The Solution: The solution was to instruct Cloudflare to explicitly set the Origin
header to the correct value before the request reaches your tunnel and thus n8n. This was achieved using a Cloudflare Transform Rule:
- In the Cloudflare Dashboard, navigate to your domain → Rules → Transform Rules.
- Create a “Modify Request Header” rule.
- Filter:
Hostname equals n8n.example.com
- Modification:
Set static
HeaderOrigin
tohttps://n8n.example.com
- Deploy the rule.
After this rule was active, the Origin
header was correctly transmitted to n8n, and the Invalid origin!
error, along with the ‘Connection lost’ message, disappeared immediately.
I hope this helps others who encounter a similar issue when running n8n behind a Cloudflare Tunnel!