Hello everyone,
I’m facing an extremely frustrating and persistent issue with my self-hosted n8n instance. I need help resolving why the “OAuth Redirect URL” for Google credentials (specifically Google Sheets, but I assume it would apply to any Google OAuth service) continues to show http://localhost:5678/rest/oauth2-credential/callback
in the n8n UI, despite having configured multiple environment variables and performed numerous debugging attempts.
My Setup Details:
- Server: AWS EC2 (Ubuntu 22.04 LTS)
- n8n Version: 1.97.1 (installed via npm)
- Domain:
https://n8n.royalmaster.academy
(configured with Nginx as a reverse proxy and Let’s Encrypt for HTTPS). - n8n Database: SQLite (default, located in
~/.n8n/database.sqlite
)
The Problem:
When attempting to set up a new Google Sheets credential (OAuth2.0), n8n presents the following redirect URL in the “OAuth Redirect URL” field within the credential setup window: http://localhost:5678/rest/oauth2-credential/callback
.
This is incorrect; it should be https://n8n.royalmaster.academy/rest/oauth2-credential/callback
. As a result, when I try to “Connect my account” and the Google authorization window opens, Google rejects the redirect URL, indicating a redirect_uri_mismatch
error.
Debugging Steps & Solutions Attempted (Unsuccessfully):
We have tried the following configurations and actions, restarting n8n (sudo systemctl daemon-reload && sudo systemctl restart n8n
or stop/start
) after each change:
- Environment Variable Configuration in
systemd
Service File (/etc/systemd/system/n8n.service
):
- Initially, I configured
N8N_EXTERNAL_HOSTNAME=n8n.royalmaster.academy
andN8N_EXTERNAL_PROTOCOL=https
. - Subsequently, I added
N8N_WEBHOOK_URL=https://n8n.royalmaster.academy/
andN8N_PORT_EXTERNAL=443
. - Finally, I added
N8N_EDITOR_BASE_URL=https://n8n.royalmaster.academy/
. - Result: Despite setting these variables in the
systemd
service file, n8n in the UI consistently showedlocalhost
for the OAuth redirect URL.
- Handling of User Configuration Files (
/home/ubuntu/.n8n/config
):
- We observed messages in the n8n log such as
Permissions 0644 for n8n settings file /home/ubuntu/.n8n/config are too >
orError loading config file /etc/n8n/config
. - Attempt 1: We deleted the
/home/ubuntu/.n8n/config
file to force n8n to use only thesystemd
environment variables.sudo rm -f /home/ubuntu/.n8n/config
- Result: The permission warning about this file temporarily disappeared, but n8n still displayed
localhost
in the UI. Shortly after, the file was either recreated, or the warning returned.
- Attempt 2 (More aggressive): We deleted the entire
/home/ubuntu/.n8n
directory (including the SQLite database and any saved configurations). This, unfortunately, resulted in the loss of all my existing workflows, but it was done to ensure a “clean start” for n8n.sudo rm -rf /home/ubuntu/.n8n
- Result: The
localhost
issue persisted, which was incredibly frustrating after losing the workflows.
- Attempt 3 (Create an empty, correctly permissioned config file in
/etc/n8n
): To prevent n8n from creating a problematic config file in the user’s directory, we tried creating an empty and correctly permissioned file in the location specified byN8N_CONFIG_FILES
.sudo touch /etc/n8n/config
sudo chown ubuntu:ubuntu /etc/n8n/config
sudo chmod 600 /etc/n8n/config
- Result: The warnings about
/home/ubuntu/.n8n/config
disappeared from the n8n logs, confirming n8n now recognized a “valid” config file. However, the OAuth redirect URL in the n8n UI still remainedlocalhost
. This led us to believe n8n was not picking up thesystemd
environment variables for this critical URL.
- Direct Editing of the User Configuration File (
/home/ubuntu/.n8n/config
):
- Since
systemd
environment variables did not seem to resolve the issue, and n8n consistently loadedUser settings loaded from: /home/ubuntu/.n8n/config
, the final strategy was to remove the empty/etc/n8n/config
file, let n8n recreate/home/ubuntu/.n8n/config
, and then directly edit that file with the configuration variables. - The content of
/home/ubuntu/.n8n/config
was set exactly as follows:JSON{ "encryptionKey": "Fbcle685l5qi06wYhGW6nuCkTxkLdWdf", "N8N_EXTERNAL_HOSTNAME": "n8n.royalmaster.academy", "N8N_EXTERNAL_PROTOCOL": "https", "N8N_WEBHOOK_URL": "https://n8n.royalmaster.academy/", "N8N_PORT_EXTERNAL": "443", "N8N_EDITOR_BASE_URL": "https://n8n.royalmaster.academy/" }
- Result: The n8n log showed
User settings loaded from: /home/ubuntu/.n8n/config
without permission warnings, and the file content was verified to be correct. However, the OAuth redirect URL in the n8n UI for OAuth STILL SHOWShttp://localhost:5678/rest/oauth2-credential/callback
!
- Exhaustive Verification in Google Cloud Console:
- We have verified in Google Cloud Console, under OAuth 2.0 Client ID > Authorized redirect URIs, that the ONLY URL listed is
https://n8n.royalmaster.academy/rest/oauth2-credential/callback
. - There are no
localhost
URLs, no HTTP URLs, or any other variations. The configuration in Google Cloud Console is confirmed correct and matches what n8n should be using.
Summary of the Persistent Problem:
It appears that n8n, for some unknown reason, systematically ignores all environment variables we attempt to provide for the OAuth redirect URL, or there is some internal logic that continues to force localhost
for this specific field in the UI, even when the underlying configuration is correct. This is highly frustrating as it prevents integration with key Google services.
Request for Help:
Has anyone encountered such a persistent issue with the OAuth redirect URL in n8n? Is there any additional configuration, environment variable, or deeper debugging step I can perform to force n8n to use the correct external URL instead of localhost
?
I appreciate any help or suggestions in advance.