Issue with OAuth Redirect URL and WEBHOOK_URL Configuration in n8n Running Behind NGINX Reverse Proxy

Description:

I am encountering an issue with setting up the Google OAuth credentials in n8n when running n8n in Docker behind an NGINX reverse proxy. Despite following the n8n documentation, perusing the posts in this community, and setting the WEBHOOK_URL environment variable in the docker-compose.yml file, the OAuth Redirect URL still points to http://localhost:5678/rest/oauth2-credential/callback instead of my public-facing domain.

Here is a summary of the steps I followed and the issue I encountered:

n8n Setup:
    n8n is running in a Docker container on my VPS.
    NGINX is acting as a reverse proxy, exposing n8n via a public domain (https://n8n.example.com).
    Google OAuth credentials are configured in n8n.

Steps Taken:
    I followed the documentation and set the WEBHOOK_URL to https://n8n.example.com/ In the docker-compose.yml and I added the following environment variables:

    environment:
      - N8N_HOST=n8n.example.com
      - N8N_URL=https://n8n.example.com
      - N8N_PROTOCOL=https
      - WEBHOOK_URL=https://n8n.example.com/

Issue:
    Despite these changes, the OAuth redirect URL is still being generated as http://localhost:5678/rest/oauth2-credential/callback in n8n.
    I also tried setting the N8N_URL and WEBHOOK_URL environment variables in the Docker container, but it did not resolve the issue.

What I Expected:
    I expected n8n to generate the correct OAuth Redirect URL and Webhook URL based on the public domain (https://n8n.example.com/) that n8n is exposed to via the reverse proxy.

What I Have Tried:
    I tried modifying the docker-compose.yml file and restarting the container.
    I also ensured that the NGINX reverse proxy is properly forwarding traffic to the correct n8n backend.

Request:
    Could you help identify why n8n is still generating the incorrect OAuth Redirect URL (localhost) despite setting the WEBHOOK_URL and N8N_URL environment variables correctly in the Docker configuration?
    Any additional configuration changes or troubleshooting steps would be greatly appreciated.

System Information:

Information on your n8n setup

  • N8N Server:
    * n8n version: 1.72.1
    * Docker version: 27.4.1, build b9d17ea
    * Docker Compose Version: v2.32.1
    * Operating System: Debian 12
* **VPS:** 
* **NGINX version:** 1.22.1-9
* **Operating System:** Debian 12


Screenshot from 2024-12-30 12-07-32

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

I have just setup n8n to run behind NGINX and it all seems to work OK.

In my docker-compose file I just have:

version: "3.7"

services:

  n8n:
    image: docker.n8n.io/n8nio/n8n
    restart: always
    ports:
      - 5678:5678
    environment:
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - n8n_data:/home/node/.n8n
      - ${DATA_FOLDER}/local_files:/files

volumes:
  n8n_data:
    external: true

The subdomain and domain are both set in the .env file.

Also, I needed to make sure my NGINX config file had the right server blocks in place too.

Hope this helps

Use the following NGINX configuration … it may help:
server {
listen 80;
server_name your-domain.com;

location / {
    proxy_pass http://localhost:5678/;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto https;
    proxy_set_header X-Forwarded-Host $host;
    proxy_set_header X-Forwarded-Port 443;
    proxy_redirect off;
}

}

Also you can get help from the To Configure Nginx Reverse Proxy on Ubuntu {Balancing} to get configuration stepwise.

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