在 Heroku 上托管 n8n(Hosting n8n on Heroku)#
本托管指南将向你展示如何在 Heroku 上自托管 n8n。它使用了:
🌐 This hosting guide shows you how to self-host n8n on Heroku. It uses:
- Docker Compose 用于创建和定义应用程序组件及它们如何协同工作。
- Heroku 的 PostgreSQL 服务 用于宿 n8n 的数据存储。
- 一个 Deploy to Heroku 按钮,只需一次点击,并进行少量配置,即可部署。
Self-hosting knowledge prerequisites
Self-hosting n8n requires technical knowledge, including:
- Setting up and configuring servers and containers
- Managing application resources and scaling
- Securing servers and applications
- Configuring n8n
n8n recommends self-hosting for expert users. Mistakes can lead to data loss, security issues, and downtime. If you aren't experienced at managing servers, n8n recommends n8n Cloud.
Stable and Beta versions
n8n releases a new minor version most weeks. The stable version is for production use. beta is the most recent release. The beta version may be unstable. To report issues, use the forum.
Current stable: 2.4.7
Current beta: 2.6.2
使用部署模板创建 Heroku 项目(Use the deployment template to create a Heroku project)#
在 Heroku 上快速开始部署 n8n 的最快方式是使用 Deploy to Heroku 按钮:
🌐 The quickest way to get started with deploying n8n to Heroku is using the Deploy to Heroku button:
这会打开 Heroku 的 创建新应用 页面。为项目设置一个名称,并选择部署项目的区域。
🌐 This opens the Create New App page on Heroku. Set a name for the project, and choose the region to deploy the project to.
配置环境变量(Configure environment variables)#
Heroku 会预先填写 app.json 文件中 env 部分定义的配置选项,这也为 n8n 使用的环境变量设置了默认值。
🌐 Heroku pre-fills the configuration options defined in the env section of the app.json file, which also sets default values for the environment variables n8n uses.
你可以更改这些值以满足你的需求。你必须更改以下值:
🌐 You can change any of these values to suit your needs. You must change the following values:
- N8N_ENCRYPTION_KEY,n8n 用它在保存到数据库之前加密用户账户详细信息。
- WEBHOOK_URL 应与你创建的应用名称匹配,以确保 webhook 使用正确的 URL。
部署 n8n(Deploy n8n)#
选择 部署应用。
🌐 Select Deploy app.
在 Heroku 构建并部署应用后,它会提供链接用于 管理应用 或 查看 应用。
🌐 After Heroku builds and deploys the app it provides links to Manage App or View the application.
Heroku 和 DNS
请参阅Heroku 文档以了解如何将你的域连接到 Heroku 应用。
更改部署模板(Changing the deployment template)#
您可以通过分叉 仓库 并从您的分叉中部署来更改部署模板。
🌐 You can make changes to the deployment template by forking the repository and deploying from you fork.
Dockerfile(The Dockerfile)#
默认情况下,Dockerfile 会拉取最新的 n8n 镜像,如果你想使用不同的或固定的版本,请更新 Dockerfile 顶部行的镜像标签。
🌐 By default the Dockerfile pulls the latest n8n image, if you want to use a different or fixed version, then update the image tag on the top line of the Dockerfile.
Heroku 和端口暴露(Heroku and exposing ports)#
Heroku 不允许基于 Docker 的应用使用 EXPOSE 命令定义暴露端口。相反,Heroku 提供了一个 PORT 环境变量,它会在应用运行时动态填充。entrypoint.sh 文件覆盖了默认的 Docker 镜像命令,以便设置 Heroku 提供的端口变量。然后,你可以通过网页浏览器访问端口 80 上的 n8n。
🌐 Heroku doesn't allow Docker-based applications to define an exposed port with the EXPOSE command. Instead, Heroku provides a PORT environment variable that it dynamically populates at application runtime. The entrypoint.sh file overrides the default Docker image command to instead set the port variable that Heroku provides. You can then access n8n on port 80 in a web browser.
Heroku 上的 Docker 限制
阅读本指南 以了解在 Heroku 上使用 Docker 的更多限制信息。
配置 Heroku(Configuring Heroku)#
heroku.yml 文件定义了你想要在 Heroku 上创建的应用。它由两个部分组成:
🌐 The heroku.yml file defines the application you want to create on Heroku. It consists of two sections:
setup>addons定义了要使用的 Heroku 插件。在此例中,是 PostgreSQL 数据库插件。build部分定义了 Heroku 如何构建应用。在这种情况下,它使用 Docker 构建包来构建基于提供的Dockerfile的web服务。
下一步步骤(Next steps)#
- Learn more about configuring and scaling n8n.
- Or explore using n8n: try the Quickstarts.