部署n8n
1. DNS 设置

2. 创建一个.env文件
创建一个项目目录来存储您的 n8n 环境配置和 Docker Compose 文件,并进入该目录:
1 | mkdir n8n-compose |
在 n8n-compose 目录下,创建一个 .env 文件来自定义 n8n 实例的详细信息。请将其修改为与您自己的信息相符:
| .env file |
|---|
| # DOMAIN_NAME and SUBDOMAIN together determine where n8n will be reachable from # The top level domain to serve from DOMAIN_NAME=example.com # The subdomain to serve from SUBDOMAIN=n8n # The above example serve n8n at: https://n8n.example.com # Optional timezone to set which gets used by Cron and other scheduling nodes # New York is the default value if not set GENERIC_TIMEZONE=Europe/Berlin # The email address to use for the TLS/SSL certificate creation SSL_EMAIL=user@example.com |
3. 创建一个本地文件夹
在项目目录中,创建一个名为 local-files 的目录,用于在 n8n 实例和主机系统之间共享文件(例如,使用“从磁盘读取/写入文件”节点):
1 | mkdir local-files |
下面的 Docker Compose 文件可以自动创建此目录,但手动创建可确保以正确的所有权和权限创建该目录。
4. 创建 Docker Compose 文件
创建一个名为 compose.yaml 的文件。将以下内容粘贴到该文件中:
1 | services: |
启动:
1 | docker-compose up -d |
此时 n8n 已经跑在:
1 | http://你的服务器IP:5678 |
5. 配置 Nginx 反代 + SSL
安装 nginx:
1 | sudo apt install nginx -y |
启用 HTTPS:
你可以选择:
方法 1:Let’s Encrypt 自动证书(最常见)
1 | sudo apt install certbot python3-certbot-nginx -y |
执行:
1 | sudo certbot --nginx -d n8n.yourdomain.com |
会自动生成 HTTPS 配置。
然后修改 Nginx 配置 /etc/nginx/sites-enabled/n8n:
1 | server { |
重启 nginx:
1 | sudo nginx -s reload |
现在可以直接访问:
1 | https://n8n.yourdomain.com |