How to Set Up a Cloudflare Tunnel for Local n8n (2025)

Dr. Violet Howard shows how to expose a local n8n instance to the internet using Cloudflare Zero Trust tunnels. Set up a tunnel named n8n-test, install the connector locally, map a public hostname to localhost:5678, then update your Docker Compose file with the new WEBHOOKURL and N8NPROTOCOL=HTTPS. This lets external services like Google and Telegram reach your workflows.
Chapters
Today I'm going to show you guys how we can take our locally hosted instance of NN and set up a Cloudflare tunnel so that we can actually talk to third-party apps and services like Google or Telegram. By the end of this video, you'll have a better understanding of how the tunnels work and how to set it all up because I'm going to walk you through it step by step. So let's get started. All right, so like I mentioned, we're going to be setting up a tunnel on Cloudflare. So you're going to go over to cloudflare.com and this is what it's going to look like, and then you're going to go ahead and create an account. So I just logged into Cloudflare and the first step is going to be you need to set up a public URL, so you need to have some sort of domain. You could go ahead and add one if you already have one, or you could buy one right here through Cloudflare for like $10 for the year. It's not going to be too bad. So you'd click on Add Domain, and then you would either have to buy a new one or transfer over a different one. And you may have seen stuff with using ngrok to create a free tunnel, but what that's going to do is give you just a free public random URL, and it's not going to be super permanent. It's going to be more temporary. So if you want to really understand more about the difference between Cloudflare and some of these other providers, I would do a quick Perplexity search. but today we're focusing on Cloudflare. Anyways, from here, what we need to do is set up a tunnel using this public domain. So we're gonna come over here and click on Zero Trust. On the left-hand side now, we're gonna go over to Networks and click on Tunnels. And then all we need to do now is add a tunnel. So I'm gonna click on Add a Tunnel. We're gonna be using a Cloudflare tunnel, so I'm gonna click on that. And now we just need to give it a name. So I'm just gonna say n8n test and then save that tunnel. And now what we have to do is install and run the actual connector locally on our device. So you're gonna choose your environment that you're operating in. So I'm gonna choose Windows. If you had a Mac, you'd click on Mac, and there's different setup instructions based on what you're using. We are using Docker, but I'm gonna go ahead and just use Windows. So follow the steps here, and then we'll meet back up after you've done this. So after you install and run that connector, you'll see that it's connected at the bottom. And if you go back out to your tunnels, you should see the one that you just set up, and it should over here say status is healthy. And now what we need to do is set up that actual domain that we connected earlier in Cloudflare. To this tunnel. So I'm gonna click on these three dots and click on configure. What we wanna do is go to the public hostname, and this is gonna be the public address that basically different apps can send data to, and then the tunnel will send that data securely to N8N. So before we set this up real quick, let me just go to an Excalidraw and actually explain how this works. So right now we have our Docker container where we did the self-hosted AI starter kit with N8N, Postgres, Qdrant, and Ollama. And all of these apps and services are able to talk to each other because they're all in the same containerized environment right here. And so what happens is if we try to access something like Gmail from this container, we're going to get blocked right here by this firewall. And vice versa, if Gmail tries to talk to us, our N8N instance, it's not going to be able to go through. Same thing with something like Telegram. So what we have to do is we have to drag in Cloudflare here to basically create a tunnel. And this is going to be some sort of, you know, actual public address. So right now we access our N8N instance through localhost:5678, which means only our local device right here where we installed everything can use it. But through Cloudflare, what we do is we set up some sort of public domain, which is going to be HTTPS. And then what happens is something like Telegram can send data to Cloudflare, Gmail can send data to Cloudflare, and then our tunnel from Cloudflare is basically just going to be able to eat right through this wall and go talk to our N8N instance. So data will be sent from Gmail to our Cloudflare public domain, and then that will get sent through the tunnel to N8N. So I know that illustration was pretty gross, but hopefully that actually makes sense in your mind now how this stuff works. So what we're going to do now is add our public hostname. So in the subdomain, I'm just going to put N8N. This is what's going to show up at the top instead of localhost. It'll be n8n.whatever. So my domain here is going to be retechcorp.org. And then what we need to do down here with the service is go to HTTP and then type in basically whatever is the localhost and the port that you're using in Docker. So right here, if I click on this, I can see my N8N is on port 5678, which is the default for N8N. So what I would do is type in localhost:5678. 5, 6, 7, 8. And now we're good to go and save this public hostname. Now that we've saved it, we have successfully saved our DNS record for this public hostname, which is going to be reaching this service, which is our locally hosted N8N. And that was super quick. Look, we can already click on this, open up this domain, which is n8n.retechcorp.org. And so right now you guys can't see it, but up in the top, rather than saying localhost, it says n8n.retech.corp. And it's an HTTPS. And now we would just have to sign into our instance. And so I just wanted to adjust the screen real quick so you guys could see. Here was the local instance that we started on, port 5678, and here's the one that we just spun up, which was n8n.retech.corp.org. And they're the exact same instance of n8n. But what's cool is you can now take this public URL and pull it up in your phone, on a different laptop, and you'd be able to access your locally hosted version of n8n. But we're not done yet, because even though we're on our public domain, if I added a webhook right here, we would see that this webhook address is still calling the localhost. So we wouldn't be able to actually access anything through here, even though we could still access other third-party stuff like Perplexity because we're able to talk through that public domain. The issue is our webhook isn't set up right, so other services can't really send data to our local instance. So like I said, there you go, Perplexity now works and other services will work, but we have to set up our actual webhook so we can do things like Telegram and Google. All right, so I close out of the NNN instances and what we're going to do is we have to go to our Docker Compose file of this container. So I'm going to open up this stack. I'm going to click on view configurations. And this is the Docker Compose file where we can edit these environment variables. So what we need to do is add a webhook URL variable and an NNN protocol variable. So basically you can see right here, this is the path in your PC or your Mac to get to this self-hosted AI starter kit. Docker Compose file. So go to that path and open up the file. So as you can see right here, I had to go to C:\Users\NateH\SelfHosted-AI-Startkit, and right here is the Docker Compose file. So when I click on that, this is going to automatically pull it up in Cursor on my computer. It may pull up in Visual Studio Code, or maybe you want to download Cursor or something else like that real quick. And now we just have to change a few things in here. So like I said, that first one's going to be a webhook URL. So I'm going to go all caps and type in WEBHOOK_URL. And you can see because I'm using Cursor, it already sort of knows what I'm going to do. But webhook_url, and then I'm going to do an equals, and then we just need to grab our actual public domain. So I'm going to click back into Cloudflare, we're going to open up this domain one more time, and then I'm just going to grab this from up here. I'm going to come back into Cursor, paste that in there, and then I just want to get rid of the, um, /home/workflow. But I am going to leave that slash at the very end after.org. And then we just need to throw in this one as well, which is any-protocol. And we just wanted to say that we are now using HTTPS. Okay, cool. So I think that should be it. What we're going to do now is just make sure we save this Docker Compose file, but it hasn't actually reflected these changes yet in N8N because we have to basically shut down the container and spin it back up. Okay, so what we're going to do is within Docker itself, I'm just going to click on this button to open up the terminal. And the first thing we need to do is we need to change our directory to get into this container basically. So I'm going to do cd and then just type in self-hosted-ai-starter-kit. We hit that and now we see that we are in the self-hosted AI starter kit directory. And now I'm just going to type in docker compose down, hit enter. And that's just going to stop what's going on right here. Okay. So we got an issue because one of the resources is still in use. I think that we should be all right though. If we just do docker compose up -d and it's going to spin that container back up. And now it's going to load back up the new n8n and everything like that with the different environment variables, and we should be good to go. Okay, there we go. So everything launched back up and it looks like we're all running healthy. We got our stuff right here, and I'm going to go back into our public URL, load that back up, and we'll open up this workflow and see if our new webhook address is changed. And as you can see, now it is n8n.retech.corp. And that's also going to be huge because if we wanted to set up some Google credentials like Google Drive Let's say we're doing this. As you guys know, you have to have an, a redirect URL to give to Google. And now because this is no longer a local one, we see that we actually can set up our Google credentials. And so anyways, just to hop back to what actually happened here, it just couldn't stop one of these resources because it was still being used. Um, and the thing is we were able to just spin everything back up and it loaded all 4 of these back up healthy. And as you guys know, we talked about how we're pulling from our volumes over here. So we're still good to go and we have all the storage running. But anyways, if you are running into issues in your terminal down here, you know, I'm not an expert at this. I have never like formally learned terminal commands, but all the large language models are pretty good at them. You just have to give enough context as to, here are my directories, here's what I'm trying to do, help me with the different commands, and they're going to be pretty good at helping you out there. So that's like honestly what I did here when I was trying to learn how to do this. Anyways, that's going to do it for this one. I hope that it was helpful, and now hopefully you understand it's not as complicated as you may have thought initially. Although I know it can be intimidating. So if you learned something new or you appreciated this video, please give it a like. Definitely helps me out a ton, and I'll see you guys in the next one. Thanks everyone.










