google oauth2 nightmare.

hey everyone hope you are well.. i have been stuck on this for 3 days its really frustrating.

my configuration:
i have pf sense at home that tunnels my wan to a vultr machine online. so my gateway is in belgium and tunnels to me in london. so running pf sense on each machine.

at home i have a VM that i want to run my self host n8n server. i installed ubuntu, docker and n8n.

I pointed a new domain to my wan ip and i can go to n8n.mydomain.com and i signed up etc.

I went to do my google oauth credentials etc and created them. popped them into n8n and when i try to go through the authentication it says error refused.

I went through all the videos and have troubleshooted everything.
the webhook url is correct as https://n8n.my domain.com and not localhost:5678.

I then proceeded to test the same credentials in google cloud with a new machine on elestio and after adding another url to the same credentials it authenticated. everything worked in elestio.

There is something i need to do with my compose yml. or perhaps how i am connecting n8n to the web?

I have created the correct firewall rules and have checked that everything is coming to port 443 or 80. even had a network engineer friend check all the rules etc.

I have been using gpt to troubleshoot and still haven’t been able to crack it. thanks in advance.

this is a copy of my compose:

services:

1) Reverse Proxy (jwilder/nginx-proxy)

nginx-proxy:
image: jwilder/nginx-proxy:latest
container_name: nginx_proxy
restart: unless-stopped
ports:
- “80:80” # HTTP
- “443:443” # HTTPS
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
- nginx_certs:/etc/nginx/certs
- nginx_vhost:/etc/nginx/vhost.d
- nginx_html:/usr/share/nginx/html
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: “true”
networks:
- superdb_network

2) Let’s Encrypt Companion

nginx-proxy-companion:
image: jrcs/letsencrypt-nginx-proxy-companion:latest
container_name: nginx_proxy_companion
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
- nginx_certs:/etc/nginx/certs
- nginx_vhost:/etc/nginx/vhost.d
- nginx_html:/usr/share/nginx/html
environment:
# This tells the companion which container is the main proxy
NGINX_PROXY_CONTAINER: nginx_proxy
depends_on:
- nginx-proxy
networks:
- superdb_network

3) Postgres

postgres:
image: postgres:15-alpine
container_name: postgres_db
restart: unless-stopped
environment:
POSTGRES_USER: n8n_user
POSTGRES_PASSWORD: n8n_pass
POSTGRES_DB: n8n_db
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- superdb_network

4) n8n

n8n:
image: n8nio/n8n:latest
container_name: n8n_server
restart: unless-stopped
environment:

  # ---- Database Settings ----
  DB_TYPE: postgresdb
  DB_POSTGRESDB_HOST: postgres
  DB_POSTGRESDB_PORT: 5432
  DB_POSTGRESDB_DATABASE: n8n_db
  DB_POSTGRESDB_USER: n8n_user
  DB_POSTGRESDB_PASSWORD: n8n_pass

  # ---- Basic Auth ----
  N8N_BASIC_AUTH_ACTIVE: "true"
  N8N_BASIC_AUTH_USER: "admin"
  N8N_BASIC_AUTH_PASSWORD: "yourSuperSecurePassword"
  N8N_PROTOCOL: "https"
  N8N_HOST: "n8n.mydomain.com"
  # ---- Secure Cookies ----
  N8N_SECURE_COOKIE: "true"

  # ---- Let’s Encrypt + Proxy ----
  VIRTUAL_HOST: "n8n.mydomain.com"
  LETSENCRYPT_HOST: "n8n.mydomain.com"
  LETSENCRYPT_EMAIL: "etcetc@gmail.com"

  # (Optional) for webhooks:
  WEBHOOK_TUNNEL_URL: "https://n8n.mydomain.com/"
  N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE: true
  N8N_TRUST_PROXY: "true"
  N8N_DIAGNOSTICS_ENABLED: "false"
  N8N_ENCRYPTION_KEY: "N8NENCRYPTIONKEY$$"
depends_on:
  - postgres
  - nginx-proxy
networks:
  - superdb_network
# No 'ports:' needed; proxy handles inbound traffic

volumes:
postgres_data:
nginx_certs:
nginx_vhost:
nginx_html:

networks:
superdb_network:
driver: bridge

what error/issue you get? ssl certificate?

This site can’t be reached

n8n.mydomain.com refused to connect.

Try:

ERR_CONNECTION_REFUSED

  1. ping and trace your subdomain url to get more details (eg. is public server ip correct?)
  2. try to remove quotes on config URL
  1. on local network or docker network you can access on n8n nstance?

we need to know where it fails: reverse proxy, on serving webpage, on firewall ecc