Webhooks do not work on a public domain

Hello everyone
I installed n8n on my VPS server using a docker container in conjunction with the nginx reverse proxy image “jwilder/nginx-proxy:latest”.
There my server configuration on docker-composes:

  • nginx-proxy docker-compose.yml
version: "3"
services:
    reverse-proxy:
        image: "jwilder/nginx-proxy:latest"
        container_name: "reverse-proxy"
        volumes:
            - "./html:/usr/share/nginx/html"
            - "./dhparam:/etc/nginx/dhparam"
            - "./vhost:/etc/nginx/vhost.d"
            - "./certs:/etc/nginx/certs"
            - "/run/docker.sock:/tmp/docker.sock:ro"
            - "/srv/reverse-proxy/proxy.conf:/etc/nginx/conf.d/proxy.conf:ro"
        restart: "always"
        networks: 
            - "net"
        ports:
            - "80:80"
            - "443:443"
    letsencrypt:
        image: "jrcs/letsencrypt-nginx-proxy-companion:latest"
        container_name: "letsencrypt-helper"
        volumes:
            - "./html:/usr/share/nginx/html"
            - "./dhparam:/etc/nginx/dhparam"
            - "./vhost:/etc/nginx/vhost.d"
            - "./certs:/etc/nginx/certs"
            - "/run/docker.sock:/var/run/docker.sock:ro"
        environment:
            NGINX_PROXY_CONTAINER: "reverse-proxy"
            DEFAULT_EMAIL: "[email protected]"
        restart: "always"
        depends_on:
            - "reverse-proxy"
        networks: 
            - "net"

volumes:
  certs:
  html:
  vhost:
  dhparam:

networks:
  net:
    external: true
  • My n8n docker-compose.yml
version: "3"
services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - WEBHOOK_TUNNEL_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - VUE_APP_URL_BASE_API=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
      - VIRTUAL_HOST=n8n.mydomain.com
      - LETSENCRYPT_HOST=n8n.mydomain.com
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n
      - ./local-files:/files

networks:
  default:
    external:
      name: net
  • My n8n .env file
# Folder where data should be saved
DATA_FOLDER=/srv/n8n/local-files

# The top level domain to serve from
DOMAIN_NAME=mydomain.com

# The subdomain to serve from
SUBDOMAIN=n8n

# DOMAIN_NAME and SUBDOMAIN combined decide where n8n will be reachable from
# above example would result in: https://n8n.example.com

# The user name to use for authentication - IMPORTANT ALWAYS CHANGE!
N8N_BASIC_AUTH_USER=login

# The password to use for authentication - IMPORTANT ALWAYS CHANGE!
N8N_BASIC_AUTH_PASSWORD=pass

# Optional timezone to set which gets used by Cron-Node by default
# If not set New York time will be used
GENERIC_TIMEZONE=Europe/Minsk

# The email address to use for the SSL certificate creation
[email protected]

Now I can go to the n8n page at n8n.mydomain.com.
But when I set up a workflow using a webhook, it does not work at the copied address either in the test or in the production link.



I also tried sending a get request to the local host and this is what came out of it:


How to make the webhook work at my external address https://n8n.mydomain.com/…?
Any help would be helpful

Hi @yatolstoy, welcome to the community!

On first sight it sounds very odd that you’re able to reach the UI under your domain name but not the webhook service. Are you opening the UI from the same machine you are sending the webhook from? If not, maybe it’s just a case of DNS changes not fully propagated yet.

Would your curl request work when sent to your domain instead of localhost?

Yes. It is the same machine.

That looks like a DNS issue to me, Are you sure the DNS record is set?

If you run the command below do you get your external IP back?

nslookup n8n.yourhost.tld

2 Likes

@jon I’m doubting that keeping WEBHOOK_TUNNEL_URL in the docker-compose.yml file is enough?
or it needs to be added in the .env file as well?

It only needs to be in the compose file.

1 Like

image
I tried the command you suggested. Here’s what she showed me.

In fact, the main domain is hosted on another server, but the ip of my VPS is registered in the A record for the n8n subdomain XXX.140.241.XXX

XXX.140.241.XXX - its is ip address of my VPS. I checked

That looks like it should be right then, It may just be that it is taking a while for DNS to go through fully. Anytime you see “Could not resolve host” it is normally always down to a DNS issue, When did you set the A record?

I set up A record yesterday afternoon. It took about 24 hours.

That should be ok, When you access the web interface for n8n do you use the DNS name as well or the IP?

I use the domain name to load the n8n interface. However, thanks to you, I started to notice strange behavior. In some cases, I can go to the n8n.mydomain.com page, but in some not. I am currently researching this issue. I guess the problem is in configuring the Nginx proxy.

To be honest I don’t think the issue is with the proxy that would result in a page not found error. A good example of this sort thing can be seen in the curl commands below.

So the first example is a host that doesn’t exist and the second is a host that exists but the page isn’t there, You may see something different like a 404 or a 500 error.

[[email protected] ~]$ curl foo.n8n.io
curl: (6) Could not resolve host: foo.n8n.io

[[email protected] ~]$ curl community.n8n.io/jfashkfhaksfashfs
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx/1.21.0</center>
</body>
</html>

You could try checking the logs of nginx to see if it is showing any errors could provide a clue.

I found a solution to the problem.
In fact, this is my carelessness.
I entered the wrong domain in the .env settings.
As a result, the webhook link in the n8n interface was generated incorrectly.
Therefore, I could not fulfill the requests.
@jon, thank for you hints. You made me think in the right direction.

3 Likes

That will do it, Glad you are sorted and up and running.

Happy automating :+1: