/n8n-tutorials

How to change the base URL in n8n?

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.

Matt Graham, CEO of Rapid Developers

Book a call with an Expert

Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.

Book a free consultation

How to change the base URL in n8n?

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:

  • Through environment variables
  • Using a .env file
  • In Docker configuration
  • Via command-line parameters

The main variables that affect the base URL are:

  • N8N\_HOST: The hostname or IP address
  • N8N\_PORT: The port number
  • N8N\_PROTOCOL: http or https
  • N8N\_PATH: Optional subfolder path

 

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):

  1. Locate your .env file (usually in the n8n installation directory)
  2. Open it with a text editor
  3. Add or modify these variables:
# 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/
  1. Save the file and restart n8n to apply the changes.

 

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:

  1. Configure your base URL to match the external URL that users will access:
N8N\_HOST=your-domain.com
N8N\_PROTOCOL=https
N8N\_PORT=443
  1. Configure your reverse proxy to forward requests to your n8n instance. Example Nginx configuration:
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:

  1. Restart your n8n instance to apply the changes
  2. Access n8n through your new URL to verify it works
  3. Create a simple webhook workflow to test if the generated webhook URLs are correct
  4. Check the "Settings" → "API" section in the n8n UI to confirm the REST API endpoint is using the correct base URL

 

Step 9: Troubleshooting Common Issues

 

If you encounter problems after changing the base URL:

  • Webhook URLs not working: Make sure your N8N_WEBHOOK_URL is correctly set and accessible from the internet if needed
  • Error when accessing n8n: Check if the port is correctly configured and not blocked by a firewall
  • Redirect loops: Ensure your reverse proxy configuration is correct if you're using one
  • Mixed content warnings: Make sure both N8N\_PROTOCOL and your actual access protocol match (both https)

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:

  • Always use HTTPS (N8N\_PROTOCOL=https) for security
  • Consider setting up proper SSL certificates with Let's Encrypt
  • Use a specific subdomain for n8n (e.g., n8n.your-domain.com) for better isolation
  • Set up authentication (N8N_BASIC_AUTH\_ACTIVE=true) if exposed to the internet

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.

Want to explore opportunities to work with us?

Connect with our team to unlock the full potential of no-code solutions with a no-commitment consultation!

Book a Free Consultation

Client trust and success are our top priorities

When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.

Rapid Dev was an exceptional project management organization and the best development collaborators I've had the pleasure of working with. They do complex work on extremely fast timelines and effectively manage the testing and pre-launch process to deliver the best possible product. I'm extremely impressed with their execution ability.

CPO, Praction - Arkady Sokolov

May 2, 2023

Working with Matt was comparable to having another co-founder on the team, but without the commitment or cost. He has a strategic mindset and willing to change the scope of the project in real time based on the needs of the client. A true strategic thought partner!

Co-Founder, Arc - Donald Muir

Dec 27, 2022

Rapid Dev are 10/10, excellent communicators - the best I've ever encountered in the tech dev space. They always go the extra mile, they genuinely care, they respond quickly, they're flexible, adaptable and their enthusiasm is amazing.

Co-CEO, Grantify - Mat Westergreen-Thorne

Oct 15, 2022

Rapid Dev is an excellent developer for no-code and low-code solutions.
We’ve had great success since launching the platform in November 2023. In a few months, we’ve gained over 1,000 new active users. We’ve also secured several dozen bookings on the platform and seen about 70% new user month-over-month growth since the launch.

Co-Founder, Church Real Estate Marketplace - Emmanuel Brown

May 1, 2024 

Matt’s dedication to executing our vision and his commitment to the project deadline were impressive. 
This was such a specific project, and Matt really delivered. We worked with a really fast turnaround, and he always delivered. The site was a perfect prop for us!

Production Manager, Media Production Company - Samantha Fekete

Sep 23, 2022