How to run n8n on your own server with an alias?

I want to run n8n on my server at the address:
my.site.com/n8n
That is, I want to use an alias.

I run the container in Docker with the parameters:

docker run -d --restart unless-stopped -it 
--name n8n 
-p 5678:5678
-e N8N_HOST="my.site.com/n8n"
-e WEBHOOK_TUNNEL_URL="https://my.site.com/n8n/"
-e WEBHOOK_URL="https://my.site.com/n8n/"
-v ~/.n8n:/root/.n8n
n8nio/n8n

Then I configure the Nginx as follows:

server {
    server_name my.site.com;
    location /n8n {
        proxy_pass http://localhost:5678;
    }
}

Then I delete the cache and restart the Nginx.

If I go to the address localhost:5678, then everything works fine and I see the n8n start page.

But if I go to the address http://my.site.com/n8n, then I should see a warning about working without encryption. But I only see a black screen.

Here is the code for the page I get in response:

<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" crossorigin src="[/assets/polyfills-BN5TIqPj.js]"></script>

<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width,initial-scale=1.0" />
<link rel="icon" href="[/favicon.ico]" />
<style>@media (prefers-color-scheme: dark) { body { background-color: rgb(45, 46, 46) } }</style>
<script type="text/javascript">
window.BASE_PATH = '/';
window.REST_ENDPOINT = 'rest';
</script> ...</script>

<title>n8n.io - Workflow Automation</title>
<script type="module" crossorigin src="[/assets/index-fCEqBD8K.js]"></script>
<link rel="stylesheet" crossorigin href="[/assets/index-Bo70cRA3.css]">
</head>
<body>
<noscript>
<strong
>We're sorry but the n8n Editor-UI doesn't work properly without JavaScript enabled. Please
enable it to continue.</strong
>
</noscript>
<div id="app"></div>
</body>
</html>

That is, I get some code, but the alias does not work. But I specified the parameter N8N_HOST=“my.site.com/n8n” !!!

What did I do wrong?

2 Likes

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:
1 Like

I am using n8n version 1.72.1.
I am using the default database.
I am not using the EXECUTIONS_PROCESS parameter of n8n in any way.
I am running n8n via Docker.
My operating system is Ubuntu 24.04.

I started two instances of n8n.

  1. Using an Alias. At address my_site_com/n8n
docker run -d --restart unless-stopped -it 
--name n8n 
-p 5678:5678 
-e N8N_ENDPOINT_REST="n8n/rest" 
-e N8N_PATH="/n8n/" 
-e N8N_HOST="my.site.com" 
-v ~/.n8n:/root/.n8n
n8nio/n8n
  1. Without using an Alias. At my_site_com
docker run -d --restart unless-stopped -it 
--name n8n2 
-p 5679:5678 
-e N8N_HOST="my.site.com" 
-v ~/.n8n:/root/.n8n n8nio/n8n

I also reconfigured the Nginx:

server {
server_name my.site.com;
location /n8n       { proxy_pass http://localhost:5678; }
location /          { proxy_pass http://localhost:5679; }
}

The instance without the Alias ​​started fine.
nero-auto.duckdns.org
Page source code:
view-source:https://nero-auto.duckdns.org/

The instance with the Alias ​​did not start.
nero-auto.duckdns.org/n8n/
Page source code:
view-source:https://nero-auto.duckdns.org/n8n/

These pages are correct. All paths are correct. But the page with the alias does not work…

What am I doing wrong?
Thanks.

Hi @beloma

I think your nginx configuration is missing some headers to handle the websocket. Can you try the below:

server {
  server_name my.site.com;
  location /n8n {
    proxy_pass http://127.0.0.1:5678;
    proxy_set_header Connection 'Upgrade';
    proxy_set_header Upgrade $http_upgrade;
    proxy_http_version 1.1;
  }

Ok. I will try this in the next 2-3 days and write about the result. I just have one free server for this.

No. It doesn’t work.
I still get a black empty page.

This page has the code:

That is, the server still gives me something to the browser!

I think we need to do something with the N8N environment variables. I’m thinking about:

  1. N8N_PATH
  2. N8N_HOST

Any news on this?? Did you fix it?

I am having the exact same issue using Version: 1.84.3 running it via Docker. This is my docker-cmopose.yml:

services:
  n8n:
    image: n8nio/n8n:latest
    container_name: n8n
    restart: unless-stopped
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      # Tells n8n to listen on port 5678
      - N8N_PORT=5678

      # Tells n8n that it is served under the /n8n path in the browser
      - N8N_PATH=/n8n
      - N8N_HOST=www.mysite.com

      - N8N_DIAGNOSTICS_ENABLES=false
      - N8N_EDITOR_BASE_URL=https://www.mysite.com/n8n

      # Webhook endpoints will be under /n8n/webhook
      - N8N_ENDPOINT_WEBHOOK=/n8n/webhook
      - N8N_ENDPOINT_WEBHOOK_TEST=/n8n/webhook-test

      # (Optional but recommended) Set your domain name so n8n
      # knows how to generate webhook URLs.
      - WEBHOOK_TUNNEL_URL=https://www.mysite.com/n8n/

      - N8N_ENDPOINT_REST=/n8n/rest

      # Authentication for n8n
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER=user
      - N8N_BASIC_AUTH_PASSWORD=password

    # A volume to persist n8n data (e.g. workflows, credentials)
    volumes:
      - ./n8n_data:/home/node/.n8n

I am not sure if there is something wrong, after a lot of time trying to debug this ChatGPT proposed this bonkers conf file:

######################################
# BLOQUE 1: Servidor en puerto 80
######################################
# - Redirige todo a HTTPS
# - Permite que Certbot use /.well-known/acme-challenge/ para renovar certificados
server {
    listen 80;
    server_name mysite.com;

    # (1) Certbot validation
    location /.well-known/acme-challenge/ {
        root /var/www/html;
    }

    # (2) Redirigir todo tráfico http a https
    return 301 https://$host$request_uri;
}

######################################
# BLOQUE 2: Servidor en puerto 443 (SSL)
######################################
server {
    listen 443 ssl http2;
    server_name mysite.com;

    # Certificados gestionados por Certbot
    ssl_certificate     /etc/letsencrypt/live/mysite.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/mysite.com/privkey.pem;
    include /etc/letsencrypt/options-ssl-nginx.conf;
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

    # ==================================================
    # (A) Ruta principal /n8n/ → pasa tal cual al contenedor
    # ==================================================
    location /n8n/ {
        proxy_pass         http://127.0.0.1:5678/;  # Observa la barra final
        proxy_http_version 1.1;

        # WebSockets y cabeceras
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }

    # ==================================================
    # (B) /n8nassets/ → reescribe internamente a /n8n/n8nassets/
    # ==================================================
    location /n8nassets/ {
        rewrite ^/n8nassets/(.*) /n8n/n8nassets/$1 break;
        proxy_pass         http://127.0.0.1:5678/;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }

    # ==================================================
    # (C) /rest/ → reescribe a /n8n/rest/
    #    si tu n8n llama a su API en /rest en vez de /n8n/rest
    # ==================================================
    location /rest/ {
        rewrite ^/rest/(.*) /n8n/rest/$1 break;
        proxy_pass         http://127.0.0.1:5678/;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }

    # ==================================================
    # (D) favicon: si n8n pide /n8nfavicon.ico
    # ==================================================
    location /n8nfavicon.ico {
        rewrite ^/n8nfavicon.ico /n8n/n8nfavicon.ico break;
        proxy_pass         http://127.0.0.1:5678/;
        proxy_http_version 1.1;

        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;
    }

    # ==================================================
    # (E) Webhooks:
    #     Si n8n define /webhook/ en raĂ­z en lugar de /n8n/webhook/
    # ==================================================
    location /webhook/ {
        rewrite ^/webhook/(.*) /n8n/webhook/$1 break;
        proxy_pass         http://127.0.0.1:5678/;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }

    # idem si tuvieras /webhook-test/:
    location /webhook-test/ {
        rewrite ^/webhook-test/(.*) /n8n/webhook-test/$1 break;
        proxy_pass         http://127.0.0.1:5678/;
        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        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;
    }

    # ==================================================
    # (F) Cualquier otra ruta → 404
    # ==================================================
    location / {
       return 404;
    }
}

I am not really sure what is the way around it…

Welcome to the community! @boredinigo

Can you please check the actual documentation and examples that exist on the docs pages, the forum and github?
ChatGPT is giving you weird stuff and also old stuff.
for example this basic authentication hasn’t been used for a long time.

Authentication for n8n

  - N8N_BASIC_AUTH_ACTIVE=true
  - N8N_BASIC_AUTH_USER=user
  - N8N_BASIC_AUTH_PASSWORD=password

for setting the host in n8n you only need to set WEBHOOK_URL and setup your revserse proxy properly.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.