这里使用Docker部署,docker-compose.yml 如下

version: '3'

volumes:
  n8n_storage:

services:
  n8n:
    image: registry.cn-shenzhen.aliyuncs.com/xiang-ai/n8n:1.95.0
    environment:
      - DB_TYPE=postgresdb
      - DB_POSTGRESDB_HOST=
      - DB_POSTGRESDB_PORT=
      - DB_POSTGRESDB_DATABASE=n8n
      - DB_POSTGRESDB_USER=postgres
      - DB_POSTGRESDB_PASSWORD=
    ports:
      - 5678:5678
    volumes:
      - n8n_storage:/home/node/.n8n


部署过程:

1、准备好POSTGRESDB

2、使用docker-compose启动


整个过程不复杂,但是有下面的坑


坑1:docker未能启动

这里需要注意,volumes 需要权限,如果配置的volumn无权限,则可能导致无法启动


坑2:需要HTTPS

否则会提示如下:

Your n8n server is configured to use a secure cookie,
however you are either visiting this via an insecure URL, or using Safari.

To fix this, please consider the following options:

  • Setup TLS/HTTPS (recommended), or
  • If you are running this locally, and not using Safari, try using localhost instead
  • If you prefer to disable this security feature (not recommended), set the environment variable N8N_SECURE_COOKIE to false

坑3:NGINX需要配置websocket

proxy_http_version                 1.1;

proxy_set_header Host           $host;
proxy_set_header Origin         https://$host;
proxy_set_header Upgrade        $http_upgrade;
proxy_set_header Connection     "Upgrade";
proxy_set_header X-Real-IP       $remote_addr;

参考:

https://github.com/n8n-io/n8n/issues/14392

https://pliszko.com/blog/post/2024-03-14-using-n8n-with-nginx-reverse-proxy


坑4:假如配置的HTTPS不是默认使用443端口,在右上角会提示Connection Error

原因是跨域,NGINX需要写死HOST及Origin,如下,假如域名是cscoder.cn,则配置如下

proxy_set_header Host           cscoder.cn;
proxy_set_header Origin         https://cscoder.cn;