How to configure a different URL for n8n's webhook

Describe the problem/error/question

I would like to have two different URLs pointed toward n8n’s instance.

For example, Let’s say I have a setup where I can access n8n’s instance from n8n.example.com. But, when building a new workflow, I would like the Webhook node to have the URL api.example.com instead of n8n.example.com.

Is this possible?

Please share your workflow

Since this is a question about setting up the instance in Docker, I am sharing my Docker-Compose file here.

version: '3.8'

services:
  postgres:
    image: postgres:11
    restart: always
    container_name: n8n_db
    environment:
      - POSTGRES_USER
      - POSTGRES_PASSWORD
      - POSTGRES_DB
      - POSTGRES_NON_ROOT_USER
      - POSTGRES_NON_ROOT_PASSWORD
    volumes:
      - /data/n8n/db:/var/lib/postgresql/data
      - ./init-data.sh:/docker-entrypoint-initdb.d/init-data.sh
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -h localhost -U ${POSTGRES_USER} -d ${POSTGRES_DB}']
      interval: 5s
      timeout: 5s
      retries: 10  

  n8napp:
    image: n8nio/n8n
    restart: always
    container_name: n8n_app
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=postgres
      - DB_POSTGRESDB_PORT=5432
      - DB_POSTGRESDB_DATABASE=${POSTGRES_DB}
      - DB_POSTGRESDB_USER=${POSTGRES_NON_ROOT_USER}
      - DB_POSTGRESDB_PASSWORD=${POSTGRES_NON_ROOT_PASSWORD}
      - EXECUTIONS_PROCESS=own
      - EXECUTIONS_TIMEOUT=-1
      - EXECUTIONS_TIMEOUT_MAX=3600
      - GENERIC_TIMEZONE=Asia/Kolkata
      - TZ=Asia/Kolkata
      - N8N_EMAIL_MODE=smtp
      - N8N_SMTP_HOST=smtp-relay.gmail.com
      - N8N_SMTP_PORT=465
      - N8N_SMTP_USER=myemailaddress
      - N8N_SMTP_PASS=${SMTP_PASSWORD}
      - N8N_SMTP_SENDER=myemailaddress
      - N8N_SMTP_SSL=true
    ports:
      - 5678:5678
    links:
      - postgres
    volumes:
      - /data/n8n/app:/home/node/.n8n
    command: /bin/sh -c "n8n start --tunnel"
    depends_on:
      postgres:
        condition: service_healthy

I am trying to run the latest version of n8n with Postgres DB using Docker in Ubuntu 22.04 LTS.

Hi @Jayavel, you can use the WEBHOOK_URL environment variable to customize your webhook URL. This is documented here.

Let me know if you run into any trouble with this :slight_smile:

Okay, I will check this and see. So, in my proxy config, can I create both n8n.example.com and api.example.com to point to the same IP address that n8n is using (http://localhost:5678)?

1 Like

Yep, pretty much. n8n will show you the WEBHOOK_URL in the platform, but you can still access the instance under your regular hostname.

2 Likes

Thank you! I was able to get it working by passing that env variable.

1 Like

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