Nicolas Bouliane

How to fix `failed to connect to host` with GitHub webhooks

Posted on

I use webhook and Github webhooks to redeploy All About Berlin when I push new changes. I’m using adnanh/webhook on an Ubuntu 24.04 VPS on DigitalOcean, behind CloudFlare.

The problem

The webhooks failed with the following message: “We couldn’t deliver this payload: failed to connect to host.”

Let’s look at the facts:

The solution

Unblock port 9000 in ufw. I ran ufw allow 9000/tcp && ufw reload. Now the port is reachable and webhook works as expected.

Now the webhook http://[server IP]:9000/hooks/deploy works, but http://allaboutberlin.com:9000/hooks/deploy still fails, still with Operation timed out (curl) and failed to connect to host (GitHub webhooks).

This is because CloudFlare is blocking port 9000, and all ports that are not in this list. At that point, there are two workarounds:
- Use one of the HTTP ports supported by CloudFlare - this is what I did. I chose port 8080, and the webhook is now at http://allaboutberlin.com:8080/hooks/deploy.
- Bypass CloudFlare and use the server’s IP address directly, and use http://[server IP]:9000/hooks/deploy as the webhook URL. This could break a long time in the future, when you forgot everything about webhooks, or someone else is responsible for this project. Not recommended.

If you choose the port 8080 route, remember to delete the ufw rule you have just added. ufw status numbered to find the rule number, and ufw delete [rule number] && ufw reload to delete the rule and apply changes.