Can't access n8n on host_port : 5678 while accessing it on other ports interferes YouTube OAuth2 API

I have been using docker to run n8n and I have been caught in an interesting loop.
When using host port 5678 that is default I have not been able to access localhost:5678 as it refused to connect.
I have tried all methods of resolving the issues. Like checking the ports if they are being used already and many other things… but none has been the solution.

So, I decided to change the host port to 7889 while container port remained 5678. This opened n8n app and I logged in. Now when I was entering credentials for YouTube OAuth2 API. I saw OAuth Redirect URL using 5678 as host port.

I used the same URL for creating OAuth Client ID. Now after doing everything here’s what I get again, same message that localhost refused to connect.

To Reproduce

Ran n8n in Docker with default internal port 5678, but localhost:5678 refused to connect.

Changed host port to 7889 — accessed n8n at localhost:7889 successfully.

Started YouTube OAuth2 setup inside n8n.

n8n auto-generated redirect URL using port 5678:
http://localhost:5678/rest/oauth2-credential/callback

Used this URL in Google OAuth Client setup.

After authentication, browser redirected to localhost:5678, which again refused connection.

Expected behavior

n8n should generate the OAuth2 Redirect URL using the actual host port (e.g., 7889) instead of hardcoding 5678,
or

Allow users to manually configure the redirect port used in OAuth2 credentials.

Operating System

Windows 11

n8n Version

1.95.3

Node.js Version

22.16.0

Database

SQLite (default)

Execution mode

main (default)

hello @shivanshu

You can change the port with the ENV N8N_PORT. However for youtube API to work, you’ll need to set up the correct URL:
Configure webhook URLs with reverse proxy | n8n Docs

2 Likes

Hi @barn4k, thank you! It was no so thoroughly explained but gave a direction.
For anyone facing the similar problem in future here is what you should do.

One thing is that you can use other host port than 5678 but you can’t authenticate youtube api for that using google oauth…

The better way is use this command
docker run -it --rm -p 7890:5678 -e N8N_PORT=5678 -e WEBHOOK_URL=http://localhost:7890 n8nio/n8n

in powershell. Let’s understand why it works..

  • This will start the container, mapping host port 7890 to container port 5678.
  • --rm means the container will be removed when you stop it.
  • The terminal will attach to the container logs.

Also the auth key will be now generated for port 7890. So n8n is on 7890 and authentication redirection too..

Have a great day ahead! Hope you don’t waste days finding the solution…

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.