When you self-host a workflow automation tool, knowing its network footprint matters right from the start. The default port for n8n is 5678, serving both its web interface and its underlying API. Whether you're running the platform locally via Node.js or deploying containers on a remote virtual private server, this port acts as the primary gateway to your automation dashboard.
If port 5678 is already occupied on your host machine, or if you need to align your deployment with strict internal network policies, you can easily override this setting. The platform relies on the environment variable N8N_PORT to handle custom port assignments. Adjusting it takes only a few moments once you understand how your specific hosting environment manages networking layers.
Modifying the Default Port in Docker
Docker remains the most popular choice for production and staging deployments. When you run n8n inside a container, you deal with two different port boundaries: the internal port inside the container (which defaults to 5678) and the external port exposed on your host machine.
To change the port your users hit externally while keeping the container's internal configuration intact, you modify the port mapping syntax in your docker-compose.yml file or your CLI run command. For example, if you want n8n to be accessible externally on port 8080, you map host port 8080 to container port 5678:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
ports:
- "8080:5678"
environment:
- N8N_HOST=0.0.0.0
volumes:
- ./data:/home/node/.n8n
Alternatively, if you need the application itself to bind to an entirely different internal port inside the container, you must pass the N8N_PORT environment variable alongside a matching port mapping:
version: '3.8'
services:
n8n:
image: n8nio/n8n:latest
container_name: n8n
ports:
- "9000:9000"
environment:
- N8N_PORT=9000
- N8N_HOST=0.0.0.0
After editing your configuration, apply the changes by recreating the container:
docker compose up -d --force-recreate
Changing the Port with Node.js and npm
If you're running n8n directly on a Linux server or local development machine via npm rather than containerization, configuration happens directly through shell environment variables.
Before launching the application, export the N8N_PORT variable in your terminal session:
export N8N_PORT=4000
n8n
To make this change persistent across system reboots, append the export command to your shell profile configuration file (such as .bashrc or .zshrc), or define it inside a dedicated .env file within your project directory and load it before startup. You can review the official n8n deployment documentation for further details on hosting strategies.
Resolving Common Networking Mistakes
Misconfigured ports often lead to connection timeouts, blank screens, or silent crashes during startup. Addressing these common pitfalls saves hours of debugging time.
- Ignoring Firewall Rules: Opening a custom port in your configuration file means nothing if your cloud provider's firewall or your local OS firewall blocks inbound traffic. Ensure rules allow TCP traffic on your chosen port.
- Mismatched Webhook URLs: When you change your port, your webhook callback URLs change too. If you don't update your instance's public URL settings using
WEBHOOK_URL, incoming triggers from external services like GitHub or Stripe will fail because they'll still point to port 5678. - Port Conflicts: If another service like a local database or web server occupies your target port, n8n will throw an immediate startup error. Check active listeners using
netstatorssbefore binding.
Frequently Asked Questions
Can I run multiple n8n instances on the same server?
Yes. Each instance requires a unique port mapping and a separate data storage volume to prevent file locks and state corruption across your workflows.
Does changing the port affect existing workflow executions?
No. Your workflow logic, credentials stored in the database, and execution histories remain intact, though active webhooks require URL updates if the port or domain changes.
Why is 5678 the default port?
The number is a playful alphanumeric nod to the word "n8n" typed out on a standard phone keypad, where 5 maps to JKL (or similar letters in early mobile naming conventions), serving as a recognizable identifier within the developer community.
How do I check if my custom port is active?
You can inspect the startup logs of your container or terminal process. Look for the initialization line confirming that n8n is ready and listening on your specified port address.