Learn how to change the base URL in n8n by configuring environment variables, .env files, Docker settings, or command-line options for secure and proper access.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
To change the base URL in n8n, modify the environment variables or configuration files that define your n8n instance's public URL. This can be done by setting the N8N_HOST, N8N_PORT, and N8N_PROTOCOL environment variables, or by updating the .env file or Docker configuration, depending on your deployment method.
Step 1: Understanding n8n Base URL Configuration
The base URL in n8n determines how the application is accessed and how webhook URLs are generated. There are several ways to configure it depending on your deployment method:
The main variables that affect the base URL are:
Step 2: Changing Base URL Using Environment Variables
If you're running n8n directly on a server, you can set environment variables before starting the application:
export N8N\_HOST=your-domain.com
export N8N\_PROTOCOL=https
export N8N\_PORT=443
export N8N\_PATH=/n8n # Optional: if you want n8n to be accessible at a subpath
Then start n8n:
n8n start
Step 3: Changing Base URL in .env File
If you're using a .env file for configuration (recommended for persistent settings):
# Base URL configuration
N8N\_HOST=your-domain.com
N8N\_PROTOCOL=https
N8N\_PORT=443
N8N\_PATH=/n8n # Optional: if you want n8n to be accessible at a subpath
# If you're behind a reverse proxy that handles HTTPS
N8N_WEBHOOK_URL=https://your-domain.com/
Step 4: Changing Base URL in Docker Deployment
If you're using Docker to run n8n, you can set environment variables in your docker-compose.yml file or in your docker run command:
Using docker-compose.yml:
version: '3'
services:
n8n:
image: n8nio/n8n
ports:
- "5678:5678"
environment:
- N8N\_HOST=your-domain.com
- N8N\_PROTOCOL=https
- N8N\_PORT=443
- N8N\_PATH=/n8n # Optional
# other configuration...
Using docker run command:
docker run -it --rm \\
-p 5678:5678 \\
-e N8N\_HOST=your-domain.com \\
-e N8N\_PROTOCOL=https \\
-e N8N\_PORT=443 \\
-e N8N\_PATH=/n8n \\
n8nio/n8n
Step 5: Changing Base URL with Command-Line Parameters
You can also set the base URL directly when starting n8n using command-line parameters:
n8n start --host your-domain.com --port 443 --protocol https --path /n8n
Step 6: Configuring a Custom Webhook URL
In some cases, you might need to specify a different URL for webhooks than the one derived from your base URL settings (especially in complex proxy setups):
export N8N_WEBHOOK_URL=https://your-custom-webhook-domain.com/
Or in .env file:
N8N_WEBHOOK_URL=https://your-custom-webhook-domain.com/
This overrides the automatically generated webhook URL.
Step 7: Working with Reverse Proxies
If you're running n8n behind a reverse proxy like Nginx or Apache:
N8N\_HOST=your-domain.com
N8N\_PROTOCOL=https
N8N\_PORT=443
server {
listen 443 ssl;
server\_name your-domain.com;
ssl\_certificate /path/to/cert.pem;
ssl_certificate_key /path/to/key.pem;
location / {
proxy\_pass http://localhost:5678;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote\_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
Step 8: Testing Your Configuration
After changing your base URL:
Step 9: Troubleshooting Common Issues
If you encounter problems after changing the base URL:
You can check the current configuration by examining the n8n logs or by accessing the "Settings" → "API" section in the UI.
Step 10: Special Considerations for Production Environments
For production deployments:
Example of a secure production configuration in .env:
N8N\_HOST=n8n.your-domain.com
N8N\_PROTOCOL=https
N8N\_PORT=443
N8N_BASIC_AUTH\_ACTIVE=true
N8N_BASIC_AUTH\_USER=admin
N8N_BASIC_AUTH\_PASSWORD=your-secure-password
Remember to restart your n8n instance after making any configuration changes to ensure they take effect.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.