How to install n8n on a Local Server and Access it Securely from Anywhere
What is n8n?
n8n is an advanced, open-source workflow automation tool designed to facilitate rapid prototyping and streamlined automation of various development processes. Think of it as an open-source, self hosted alternative to Zapier. It’s intuitive, visual interface empowers developers to seamlessly connect APIs, services, and integrations without extensive coding, dramatically accelerating workflow creation and experimentation.
Moreover, n8n supports extensive AI integrations, allowing seamless incorporation of AI functionalities into workflows, unlocking opportunities for sophisticated automation and process optimisation.
Access it Securely from Anywhere Using Docker and Cloudflared
Why We Chose Docker and Cloudflared
We opted to self-host n8n using Docker for the following reasons:
- Complete control over data security and resource management.
- Scalability and ease of deployment.
- Custom integration with additional NPM modules and services such as
ffmpeg
.
To securely expose our n8n instance externally, we integrated Cloudflared (Cloudflare Tunnel), which:
- Ensures secure, encrypted connections without opening firewall ports directly.
- Simplifies external access via Cloudflare’s robust global infrastructure.
- Enhances security by masking the server’s IP address.
Step-by-Step Installation and Configuration
Step 1: SSH into Your Server
Wondering how to get a server? Read How to deploy an ubuntu server before continuing
ssh ubuntu@your_server_ip
Step 2: Deploy n8n with Docker
Run n8n in a Docker container using a custom environment file:
docker run -d --restart=always --env-file ./.env-n8n --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
Create and populate your .env-n8n
file as follows:
DOMAIN_NAME=n8n.yourdomain.com
GENERIC_TIMEZONE=Europe/Berlin
Step 3: Verify and Manage Your Docker Container
Check logs:
docker logs n8n
Stop your container:
docker stop n8n
Step 4: Update Your n8n Container
Regular updates ensure security and functionality improvements:
docker stop n8n
docker rm n8n
docker run --pull always -d --restart=always --env-file ./.env-n8n --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
Setting Up Cloudflare Tunnel with Cloudflared
Cloudflare Tunnel (Cloudflared) securely routes traffic through Cloudflare without exposing your server IP directly.
Running Cloudflared in Docker (Recommended Method)
Execute the following command to run Cloudflared in a Docker container with host network mode:
docker run -d --restart=always --network="host" --name cloudflared cloudflare/cloudflared:latest tunnel --no-autoupdate run --token YOUR_CLOUDFLARE_TUNNEL_TOKEN
Managing Cloudflared Container
Stop and remove the Cloudflared container as needed:
docker stop cloudflared
docker rm cloudflared
Why Use Host Network Mode?
- Simplifies the setup by allowing Cloudflared to easily connect with local services.
- Eliminates the complexity of Docker’s internal networking.
- Ideal for setups managing multiple services through Cloudflare Tunnel.
Security Considerations
- Using the host network mode removes Docker’s network isolation, meaning careful consideration of the security context is required.
- Ensure your server is otherwise secure and well-monitored.
How to Access n8n
Your n8n application will be securely accessible at:
https://n8n.yourdomain.com
Application and Utility of n8n
We utilise n8n extensively for:
- Creating agile production workflows with minimal code.
- Rapid prototyping of complex automations.
- Integrating AI into existing and new processes, significantly enhancing our operational efficiency.
Getting Started with n8n
Explore these resources to jumpstart your n8n automation journey:
Advanced Implementations
We’ve successfully transitioned various n8n workflows into full-fledged applications, including Python-based AI chatbots. Further details on such integrations:
- More posts on advanced implementations coming soon!
Taking things further with Docker Compose
While this guide provides a solid foundation for running n8n using Docker, it only scratches the surface of what’s possible. For a more advanced implementation using Docker Compose with custom NPM modules and enhanced functionality, check out our detailed guide on How to run n8n with docker compose to use custom NPM modules.
The Docker Compose setup enables you to:
- Integrate custom NPM modules like @tryfabric/martian for enhanced capabilities
- Configure complex email settings using AWS SES
- Manage persistent data storage more effectively
- Scale your automation workflows with better resource management
Using this setup, we’ve greatly enhanced our automation capabilities, boosted development efficiency, and maintained optimal security standards. Explore n8n today, and unlock a world of powerful automation possibilities!