Invite emails contain incorrect port in URL when using nginx reverse proxy with subpath

Describe the problem/error/question

When I send invite emails from n8n, the URL in the email includes port :5678, like this:

http://<m,y-domain>:5678/n8n/signup?inviterId=...

However, I’m exposing n8n via an nginx reverse proxy at:

https://<your-domain>/n8n

Port 5678 is not publicly accessible, so these links don’t work externally.
How can I ensure that invite links use the correct public URL without the port?

What is the error message (if any)?

This is not workflow-related. It’s about deployment and URL generation.

Information on your n8n setup

n8n version: 1.89.2
Database: PostgreSQL
n8n EXECUTIONS_PROCESS: default
Running n8n via: Docker (compose)
Operating system: Ubuntu (hosted on AWS EC2)

Relevant docker-compose environment variables:

version: '3.8'

services:
  n8n:
    image: n8nio/n8n
    restart: always
    environment:
      - N8N_HOST=<my-domain>
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - N8N_PATH=/n8n
      - N8N_EMAIL_MODE=smtp
      - N8N_SMTP_HOST=smtp.gmail.com
      - N8N_SMTP_PORT=465
      - N8N_SMTP_USER=<myuser>
      - N8N_SMTP_PASS=<mypass>
      - N8N_SMTP_SENDER=<mysender>
      - N8N_SMTP_SSL=true
      - N8N_GENERIC_CONFIG_TRUST_PROXY=true
      - N8N_RUNNERS_ENABLED=true
      - N8N_PROXY_HOPS=1
      - N8N_METRICS_INCLUDE_IN_HEADERS=false
      - N8N_WEBHOOK_URL=https://<my-domain>/n8n
      - DB_POSTGRESDB_DATABASE=<mydb>
      - DB_POSTGRESDB_USER=<myuser>
      - DB_POSTGRESDB_SCHEMA=n8n
      - DB_POSTGRESDB_PASSWORD=<mypass>
      - GENERIC_TIMEZONE=Asia/Tokyo
      - N8N_SECURE_COOKIE=false
    ports:
      - "5678:5678"
    volumes:
      - n8n_data:/home/node/.n8n

volumes:
  n8n_data:

nginx config:

server {
    listen 443 ssl;
    server_name <your-domain>;

    ssl_certificate /etc/letsencrypt/live/<your-domain>/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/<your-domain>/privkey.pem;

    location /n8n{
        proxy_pass http://localhost: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;
    }
}

Any help or clarification is greatly appreciated. Thank you!

I used this in Nginx, maybe you can try it

	server {
		listen 443 ssl;
		server_name hidden.com;
				
		ssl_certificate      C:\\nginx-1.27.2\\ssl\\k8saiinpocket.com\\hidden.pem;
		ssl_certificate_key  C:\\nginx-1.27.2\\ssl\\k8saiinpocket.com\\hidden.key;
		ssl_protocols TLSv1.2 TLSv1.3;
		ssl_session_cache shared:SSL:1m;
		ssl_session_timeout 10m;
		ssl_ciphers  HIGH:!aNULL:!MD5;
		ssl_prefer_server_ciphers  on;

		location / {
		
			chunked_transfer_encoding off;
			proxy_cache_bypass                 $http_upgrade;
			proxy_ssl_server_name              on;

			proxy_pass https://ingress_controller/;
			proxy_http_version 1.1;
			proxy_buffering off;
			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;
			proxy_set_header X-Forwarded-Server $host;
			proxy_set_header X-Forwarded-Host $host:$server_port;
			
			proxy_ssl_verify off;
			proxy_ssl_session_reuse on;
			proxy_read_timeout 900;
		}

		error_log C:\\nginx-1.27.2\\logs\\k8s_ingress_error.log;
		access_log C:\\nginx-1.27.2\\logs\\k8s_ingress_access.log;
	}
1 Like

Hi everyone, just wanted to follow up and confirm that the issue is now resolved
The root cause was an incorrect environment variable.
I had originally set:

N8N_WEBHOOK_URL=https://my-domain.com/n8n

But it turns out that the correct variable is:

WEBHOOK_URL=https://my-domain.com/n8n

Once I made this change and restarted the container, the invite emails stopped appending the incorrect port (:5678) and everything now works as expected — including subpath routing with Nginx.

Thanks to everyone who helped and I hope this helps someone else facing the same issue!

1 Like

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