Self-hosting n8n is a good way to own your automation layer. It’s also easy to end up with n8n reachable from the internet over plain HTTP while your firewall tells you it isn’t. I found this on a server I built for my own business, and it’s worth checking on yours.
The problem: Docker and ufw don’t agree
A typical self-hosted setup runs n8n in Docker Compose, publishes port 5678, puts nginx in front with a TLS certificate, and uses ufw to close everything except ports 80 and 443.
The catch is that when Docker publishes a port, it adds its own firewall rules, and those are evaluated before ufw’s. So ufw can say port 5678 is closed while Docker is still letting traffic through to the container.
I checked it directly. After removing the ufw rule that allowed 5678, a request from outside the server to port 5678 still returned 200. n8n was reachable over plain HTTP, skipping nginx and TLS entirely.
How to check yours
From a machine outside the server, try the n8n port directly:
curl -s -o /dev/null -w "%{http_code}\n" http://YOUR-SERVER-IP:5678/
If that prints 200, or anything other than a connection failure, n8n is reachable without going through your proxy, whatever ufw says.
The fix
- Publish the port on localhost only. In your Compose file, change the port mapping from
"5678:5678"to"127.0.0.1:5678:5678". The container is then only reachable from the server itself. - Point nginx at localhost. Use
proxy_pass http://127.0.0.1:5678;so nginx is the only way in. - Re-run the curl test from outside. It should now fail to connect, while your HTTPS address keeps working.
- Narrow the cloud firewall too. On Google Cloud, the rule allowing web traffic only needs TCP 80 and 443.
Two more things I’d check on the same server
- IPv6. If your nginx site has no explicit
listenlines, it may only answer on IPv4, and IPv6 visitors land on the server’s default site instead. Addlisten 80;andlisten [::]:80;before running certbot, so the HTTPS configuration covers both. - Secure cookies. Set
N8N_SECURE_COOKIE=trueonce n8n is only served over HTTPS.
If your DNS is on Cloudflare
Keep the n8n hostname’s record set to DNS only (the grey cloud). With Cloudflare’s proxy turned on, Cloudflare terminates TLS itself, which can break certbot renewals against your server. If you want the proxy, plan your certificate setup around it first.
The rest of a solid self-hosted setup
On a client build I set up n8n end to end on Google Cloud: a static IP, Docker running n8n with Postgres and Redis, nginx on a dedicated subdomain, and automatic restart through systemd, tested through a full reboot and healthy again in under a minute. Restart behaviour is worth testing on purpose, before an unplanned reboot does it for you.
Self-hosting is still a good choice when you want control over the data and the server. It just needs to be checked from the outside, not only configured from the inside.
Need this done for you?
Automation that goes past HubSpot’s native workflows, on n8n or Zapier, hosted where you want it.
n8n AutomationWritten by Ali Ismail, who runs TechPad and builds HubSpot integrations, migrations and automation.