azure - 如何在Azure App Service中配置多个虚拟应用程序?

标签 azure iis azure-web-app-service web-config

我正在使用 Express 创建 API 并尝试在 Azure 应用服务上部署。我已成功在默认路径 site\wwwroot 上部署并运行它。

它工作正常,但我想将其部署在不同的路径site\backend上。因此,我为其设置了路径映射并部署了完全相同的代码,但它给出了错误。

我删除了 site\wwwroot 中的代码,认为这可能是因为 web.config 重复且结果相同。我还重新启动了应用服务,但仍然无法工作。

知道如何解决这个问题吗?

错误

Azure App Service - Page Isn't Working Error 500

路径映射

Azure App Services Path Mapping

应用程序设置

SCM_DO_BUILD_DURING_DEPLOYMENT=true
WEBSITE_NODE_DEFAULT_VERSION=~16

网页配置

<?xml version="1.0" encoding="utf-8"?>
<!--
     This configuration file is required if iisnode is used to run node processes behind
     IIS or IIS Express.  For more information, visit:

     https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config
-->

<configuration>
  <system.webServer>
    <!-- Visit http://blogs.msdn.com/b/windowsazure/archive/2013/11/14/introduction-to-websockets-on-windows-azure-web-sites.aspx for more information on WebSocket support -->
    <webSocket enabled="false" />
    <handlers>
      <!-- Indicates that the server.js file is a node.js site to be handled by the iisnode module -->
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <!-- Do not interfere with requests for node-inspector debugging -->
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <!-- First we consider whether the incoming URL matches a physical file in the /public folder -->
        <rule name="StaticContent">
          <action type="Rewrite" url="public{PATH_INFO}"/>
        </rule>

        <!-- All other URLs are mapped to the node.js site entry point -->
        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>
    
    <!-- 'bin' directory has no special meaning in node.js and apps can be placed in it -->
    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <!-- Make sure error responses are left untouched -->
    <httpErrors existingResponse="PassThrough" />

    <!--
      You can control how Node is hosted within IIS using the following options:
        * watchedFiles: semi-colon separated list of files that will be watched for changes to restart the server
        * node_env: will be propagated to node as NODE_ENV environment variable
        * debuggingEnabled - controls whether the built-in debugger is enabled

      See https://github.com/tjanczuk/iisnode/blob/master/src/samples/configuration/web.config for a full list of options
    -->
    <!--<iisnode watchedFiles="web.config;*.js"/>-->
  </system.webServer>
</configuration>

最佳答案

我能够在 Azure 应用服务中的站点文件夹下部署多个应用程序。 请按照以下步骤操作。

  • 在 Azure 门户中使用运行时堆栈节点创建应用服务。

  • 默认情况下,将创建带有 / 的虚拟路径和物理路径 site\wwwroot

  • 在 VS 中,创建 2 个新的 Express App,并将其命名为 Exp1Exp2

  • 在 Azure 门户中,添加名为 Exp1Exp2 的新虚拟目录enter image description here

  • 确保应用程序名称和虚拟路径名称相同。

  • 在 Azure 应用服务 => 概述中,您将找到一个下载发布配置文件(获取发布配置文件)的选项。 enter image description here

  • 在 VS 中,右键单击要部署的项目文件夹 (Exp1),然后选择导入配置文件。在浏览选项中选择下载的发布配置文件并继续后续步骤。 enter image description here

在“发布连接”设置中,更改站点名称,如下所示“保存并发布”。 enter image description here

对 App 2 (Exp2) 重复相同的步骤。 您可以看到包含源文件的文件夹 Exp1Exp2 已创建,并且 wwwroot 文件夹也存在。 enter image description here

关于azure - 如何在Azure App Service中配置多个虚拟应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74010386/

相关文章:

azure - webapi 不适用于 azure

powershell - 如何使用 Azure Active Directory PowerShell V2 'Grant Permissions'

iis - 如果更新虚拟机大小,Azure 虚拟机软件会发生什么情况?

azure - 将 Python 应用程序部署到 Azure 应用服务的 Github 工作流

azure - azure 网站的应用程序池超时

azure-devops - 将多个管道作业的结果合并到 azure web 应用程序包中

Azure 虚拟机 - 存储帐户的用途

windows - 如何获取 Azure 角色的初始配置?

windows - 用于验证 IIS 设置的 Powershell 脚本

node.js - IIS 反向代理从其背后的 NodeJS 获取 404