I have a request: Would it be possible for you to write a simple guide on how to make a local n8n container accessible via SSL/HTTPS using Docker Compose? Specifically, I would like to know how to create an SSL certificate and use it for this setup.
I am new to both n8n and Docker, which is why I am asking this question. This topic is particularly important because a webhook requires a unique, externally accessible URL.
I have also been thinking about an alternative solution: Would it be possible to use a Fritzbox (router) that already has its own domain and an SSL certificate? Could the traffic be forwarded from there to the n8n container, potentially eliminating the need for a separate SSL certificate within the n8n installation?
I’m running a similar case and solved the SSL and exposing it externally using a Cloudflare Tunnel (Create a locally-managed tunnel · Cloudflare Zero Trust docs).
It’s not hard to set up once you already have n8n and nginx running locally, but I can’t provide you a complete step-by-step onDockerr because I’m not running it withDockerr, but it shouldn’t be hard to find more detailed instructions.
The easiest way to expose your local n8n instance with SSL is to use Ngrok for port forwarding, as it already has an SSL-secured domain. This avoids the need to configure SSL, that you would’ve using your router.
You can set it up in seconds with:
ngrok http 5678
This is especially useful if you need to receive webhooks without dealing with networking configurations.
I recommend using ngrok for your setup, as it provides a simple, zero-config CLI tool for port forwarding and obtaining an SSL certificate. Even though your Fritzbox router may already have an SSL certificate, ngrok is often the safer and easier solution.
Securing n8n with Ngrok:
Ngrok is a powerful tool that allows you to securely expose local servers to the internet. It also automatically handles SSL encryption, making the setup process much easier.
Steps to Secure n8n with Ngrok:
Step 1: Install ngrok
Start by downloading and installing ngrok from here.
Step 2: Run n8n Locally
Ensure that your n8n instance is running locally, typically on port 5678.
Step 3: Launch ngrok
Open a terminal and run the following command to expose n8n to the internet:
ngrok http 5678
This will start ngrok and provide a public HTTPS URL for your local n8n instance. Ngrok automatically handles SSL for the URL it generates.
Step 4: Use the ngrok URL
Once you run the command, you’ll see something like this:
You have to add 2 new variables into the environment variables of your docker container as seen in this example using docker compose Docker Compose | n8n Docs in the environments section.
These 2 being N8N_HOST=xxxxxxxx.ngrok.io and N8N_PROTOCOL=https.
@Aurangcool if you set up your n8n instance using Docker Compose, you can add the required environment variables to the docker-compose.yml file under the environment section. And re-run docker-compose up -d.
If you didn’t use Docker Compose, you’ll need to stop your current Docker container and remove it. After that, run the following command to start a new container with the necessary environment variables:
Hello Knight, it worked thank you. But why the domain over ngrok.com changes time to time? the problem is that when ist needs how can i use the webhook? CAN I USE THIS ONE? Pinggy - Simple Localhost Tunnels this is cheper and faster?! What do you think?
Having now done this the hard way, I see the virtue of separating the SSL from the n8n container… but I guess I’ll always have the memories (and a stronger understanding of docker).
For anyone else who wants to do it the hard way, this configuration works in a situation where:
n8n needs to connect to internal resources with “enterprise” certs
n8n needs to connect back to its own API
n8n needs to connect to public services through a MitM SSL inspection layer
This config assumes you have already updated the host-level CA list using (for Ubuntu:
sudo update-ca-certificates --verbose
Once curl or wget can make HTTPS connections at the host level, you can go a level deeper with n8n:
My docker compose:
services:
n8n:
image: n8nio/n8n:latest
restart: unless-stopped
hostname: ${FQDN} # necessary for correct docker name resolution of self
ports:
- "5678:5678"
environment:
- NODE_EXTRA_CA_CERTS=/etc/ssl/certs/ca-certificates.crt # node needs the custom CAs
- N8N_HOST=${FQDN}
- N8N_PORT=5678
- N8N_PROTOCOL=https
- N8N_SSL_CERT=/ssl/n8n.pem
- N8N_SSL_KEY=/ssl/n8n.key
- TZ=Etc/UTC
- GENERIC_TIMEZONE=Etc/UTC
- N8N_RUNNERS_ENABLED=true
- N8N_SECURE_COOKIE=false
volumes:
- n8n_data:/home/node/.n8n
- /etc/n8n/ssl:/ssl:ro # bind to the container's cert
- /etc/ssl/certs/:/etc/ssl/certs/:ro # bind to the host's CA list
volumes:
n8n_data:
external: true