N8n selfhosted on vps with own domain

Issues with Google OAuth in n8n Docker Setup

Hello, I’m hosting n8n on my VPS and connected it to my subdomain. I can open it through this domain so I initially thought everything was working fine.

Now I wanted to connect my Google credentials and have done everything necessary.

Unfortunately, when signing in to my Google account, I get the following error: ‘ERR_CONNECTION_REFUSED’ when clicking the ‘Sign in with Google’ button.

I’ve already completed the following steps:

  1. Created a Google Cloud project and configured the OAuth credentials
  2. Set the OAuth Redirect URL in the Google Cloud Console to ‘https://my-domain.com:5678/rest/oauth2-credential/callback
  3. In my docker-compose.yml, I have the following configuration:
  • n8n with Traefik as reverse proxy
  • Port 5678 exposed
  • N8N_HOST and WEBHOOK_TUNNEL_URL correctly set
  1. Configured the firewall on my VPS so that port 5678 is accessible

When I directly ‘curl’ the callback URL, I get a response from the server, but the actual OAuth process doesn’t work.

Has anyone had similar problems or knows how to fix this? I suspect it has something to do with forwarding the OAuth requests through Traefik.

Here’s my docker-compose.yml for further reference:

version: "3"
services:
 traefik:
   image: "traefik:latest"
   container_name: traefik
   restart: always
   command:
     - "--api.insecure=false"
     - "--providers.docker=true"
     # More Traefik configuration
   ports:
     - "80:80"
     - "443:443"
   volumes:
     - "./letsencrypt:/letsencrypt"
     - "/var/run/docker.sock:/var/run/docker.sock:ro"

 n8n:
   build:
     context: .
     dockerfile: Dockerfile
   container_name: n8n-container
   restart: unless-stopped
   ports:
     - "5678:5678"
   environment:
     - N8N_HOST=my-domain.com
     - N8N_PORT=5678
     - N8N_PROTOCOL=https
     - WEBHOOK_TUNNEL_URL=https://my-domain.com:5678
   # More configuration
![Screenshot 2025-03-18 193302|690x332](upload://65hdViKKXTeWvONkFZ7faATa6mA.png)


Thanks in advance for your help!

It looks like you’re almost there! One extra step is to add the required OAuth scopes before clicking “Sign in with Google” Here’s a simple breakdown:

First:
Enable the needed API (for example, Google Drive):
image

Then:
Click here to check which scopes are needed:

After that:
The “Sign in with Google” window will show the required scopes. You can search for and add each of them:

Finally:
Continue with the “Sign in with Google” process.

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