Hello, the Webhook URL will not set in my self-hosted n8n instance. I’ve got a Cloudflare tunnel setup (I can access the n8n instance and login using the public URL xx.domain.com:5678) and I know it is working. Even if that wasn’t working, it still doesn’t have an effect on my issue:
No matter what I change in my Environment variables, it will not update the OAuth Redirect URL from the default localhost:5678 to my public URL.
Here are the environment variables I have set:
N8N_EDITOR_BASE_URL=
N8N_PROTOCOL=https
N8N_HOST=
WEBHOOK_URL=https://
N8N_PROXY_HOPS=1
I feel like I’m going round in circles. Either I’m missing something obvious that I hope someone can point out or I need to wipe everything and start again because I’ve gone down a rabbit hole for the past 3 weeks trying to figure this out.
Hi @minkeyboy2004, welcome!
With the npm version of n8n, have you tried exporting those variables in the shell before running n8n? Like run these commands:
and then run n8n start. Mostly this is the fix, as for n8n, sometimes the environment variables you have set are not reachable. Try this and let me know if that fails.
Make sure you are setting those variables in compliance with this:
Sorry I probably should have mentioned how I set them! Yes I’ve been running them with “export” in-front of them and not storing them in a file. When I run “env” in the CLI, I get all those variables back with my defined values and have stopped and then started the instance after every change but to no avail.
It may also be worth mentioning, I did attempt to deploy this via the Docker method but I needed this to run as a service and have external monitoring as I’m running a headless Linux server with a few other things on it at the moment. I did also run into the same issue of trying to set the Webhook URL, hence I scrapped it and started fresh with an npm install.
Welcome @minkeyboy2004 to our community! I’m Jay and I am a n8n verified creator.
For npm install, the variables need to be in a .env file or set in the same shell session before you start n8n. The most reliable way is to create a ~/.n8n/.env file (n8n picks it up automatically) or set them in your systemd service file under [Service] with Environment="WEBHOOK_URL=https://yourdomain.com/". Also - the key one is WEBHOOK_URL, not N8N_HOST. Set WEBHOOK_URL=https://yourdomain.com/ (with trailing slash) and restart n8n. Check Settings > n8n API in the UI after restarting to confirm the webhook URL has updated.
I’ve done what you suggested and created an environment file under the n8n directory ~/.n8n/.env and restarted n8n but the callback URL is still showing as “localhost”
I’ve also tried removing the N8N_HOST and Editor base URL since I took that screenshot, restarting it after everything change but it still shows localhost:5678
I think you have solved it! I use PM2 Process Manager so I can get live metrics of the app without having to login to the server and check. I would normally start it using “pm2 start n8n” but since creating both the .env file + starting it by just using “n8n” it appears to be working so whatever wrap around pm2 is doing, clearly is breaking it.
For anyone else who stumbles on this in future. It appears the PM2 was stopping n8n from picking up the environment variables. If I figure out how to use PM2 whilst setting the environment variables, I will update this.
Ah how great @minkeyboy2004
I’m so happy! I appreciate you marking the answer as a solution so other members can find help more easily.
Come back whenever you need to
@minkeyboy2004 glad you got it working! For the PM2 + env vars issue, the fix is to use a PM2 ecosystem file (ecosystem.config.js) and set your env vars there under the env key, then run pm2 start ecosystem.config.js. That way PM2 passes the variables directly to the process instead of relying on it to read a .env file, which PM2 doesn’t do by default.