我在 Visual Studio 解决方案中有两个 ASP.NET Core 应用程序(API 和 UI),想要部署到 Linux 上的单个 AWS Elastic Beanstalk 并使用 Kestrel 服务器(单个 URL 和不同端口)。我怎样才能做到这一点?
最佳答案
AWS Elastic Beanstalk 支持在 Linux 上的 .NET Core 中运行多个应用程序。 Elastic Beanstalk 的 .NET Core on Linux 文档包含有关 Bundling applications 的有用部分其中包括一个示例 zip 文件,其中包含两个要一起部署在一个 Elastic Beanstalk 实例上的应用程序:dotnet-core-linux-multiple-apps.zip .
您可以部署 dotnet-core-linux-multiple-apps.zip
直接将文件发送到 Elastic Beanstalk 以查看其运行情况。有关如何将 zip 文件部署到 Elastic Beanstalk 的明确说明,请参阅 Tutorial - .NET Core on Linux指导。在您的情况下,您需要上传示例 dotnet-core-linux-multiple-apps.zip
而不是教程引用的单个应用程序 zip。
每个已部署的应用程序将在每个应用程序的 launchSettings.json
中定义的本地端口上的 Elastic Beanstalk 应用程序服务器实例上运行。文件。请注意,此文件在 dotnet-core-linux-multiple-apps.zip
中包含的任何一个示例应用程序中都不可见。存档,因为这些应用程序已经用 dotnet publish
编译了命令被包含在 zip 文件中之前。
告诉 Elastic Beanstalk 将哪些路径映射到每个正在运行的应用程序的本地端口的相关配置位于 platform/nginx/conf.d/elasticbeanstalk/01_custom.conf
中。文件,位于 dotnet-core-linux-multiple-apps.zip
内.请参阅 Linux 上的 .NET Core proxy server config documentation有关此文件包含的内容的更多信息。请注意,默认情况下,Elastic Beanstalk 将映射 /
到港口5000
,因此您只需为您的其他应用程序指定额外的反向代理映射,假设您的一个应用程序配置为在默认端口上运行 5000
.
所以,总结一下:
通过查看每个应用程序的
launchSettings.json
确保您知道每个应用程序将在哪个本地端口上运行。文件。构建您的每个 .NET Core 应用程序并将它们放在一个文件夹中,您将压缩该文件夹以创建要部署到 Elastic Beanstalk 的项目。为了争论,我们称这个文件夹为
build
。 .在你的
build
文件夹(示例名称,见上文),创建一个platform/nginx/conf.d/elasticbeanstalk/01_custom.conf
描述如何将每个应用程序的端口映射到所需路径的文件。压缩您的“build”文件夹。有关此步骤的帮助,请参阅 Configure an application source bundle documentation
将您的源包部署到 Elastic Beanstalk。有关此步骤的帮助,请参阅 Managing application versions文档。
关于linux - 在 Linux 上的 AWS Elastic Beanstalk 中部署多个 ASP.NET Core 应用程序(使用 Kestrel 服务器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65878348/