【问题标题】:How to configure web.config for multiple virtual applications in Azure App Service?如何为 Azure App Service 中的多个虚拟应用程序配置 web.config?
【发布时间】:2019-02-12 11:03:32
【问题描述】:

我试图让多个 Node.js 应用程序在同一个 Azure 应用服务实例中并行工作。我尝试为每个 Node.js 应用程序创建一个虚拟应用程序,但我经常收到服务器错误(代码 500)。我使用 ZipDeploy 或 Azure DevOps 来部署我的应用程序。

我怀疑问题可能是与我的应用程序关联的 web.config 文件不正确。

以下是我的设置的一些详细信息:

在我的应用服务实例的应用程序设置菜单中,我转到虚拟应用程序和目录设置并输入以下内容:

/                         site\wwwroot                        Application x
/mysite1                  site\wwwroot\mysite1                Application x
/mysite2                  site\wwwroot\mysite2                Application x

我的 wwwroot 目录如下所示。为了确保问题不是来自代码本身,我对所有三个都使用了相同的 Node.js 应用程序:

index.html
server.js
scripts
web.config (*)
----- mysite1
      |----- index.html
      |----- server.js
      |----- scripts
      |----- web.config (**)
----- mysite2
      |----- index.html
      |----- server.js
      |----- scripts
      |----- web.config (***)

我为他们三个使用默认的 web.config 文件 (provided by Kudu):

<?xml version="1.0" encoding="utf-8"?>

<configuration>
  <system.webServer>

    <webSocket enabled="false" />
    <handlers>
      <add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
    </handlers>
    <rewrite>
      <rules>
        <rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
          <match url="^server.js\/debug[\/]?" />
        </rule>

        <rule name="StaticContent">
          <action type="Rewrite" url="public{REQUEST_URI}"/>
        </rule>

        <rule name="DynamicContent">
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/>
          </conditions>
          <action type="Rewrite" url="server.js"/>
        </rule>
      </rules>
    </rewrite>

    <security>
      <requestFiltering>
        <hiddenSegments>
          <remove segment="bin"/>
        </hiddenSegments>
      </requestFiltering>
    </security>

    <httpErrors existingResponse="PassThrough" />

  </system.webServer>
</configuration>

使用此配置,我可以毫无问题地访问 https://myappservice.azurewebsites.net/,但 https://myappservice.azurewebsites.net/mysite1 仅返回服务器错误。

我尝试按照类似问题中的说明从子目录(** 和 ***)中的 web.config 文件中删除处理程序,但无济于事。

这三个文件的正确配置是什么?我想重写规则需要调整,但我不确定每个规则的确切期望值是多少。

【问题讨论】:

  • 您可以接受您的回复作为关闭此问题的答案:)

标签: azure azure-web-app-service iisnode


【解决方案1】:

我终于设法通过 IIS 日志(Kudu 上的/LogFiles/W3SVC.../)查明了确切的问题:

ModuleName="RewriteModule", Notification="SEND_RESPONSE", HttpStatus="500", HttpReason="URL Rewrite Module Error.", HttpSubStatus="52", ErrorCode="Cannot create a file when that file already exists.
 (0x800700b7)", ConfigExceptionInfo="\\?\D:\home\site\wwwroot\mysite1\web.config ( 16) :Cannot add duplicate collection entry of type 'rule' with unique key attribute 'name' set to 'NodeInspector'
"

需要更改的是子 web.config 文件中的处理程序和规则名称,以便它们不会与父 web.config 文件中的名称发生冲突。现在一切正常。

【讨论】:

  • 我尝试过同样的操作,但在虚拟应用程序中找不到 404。请问有什么建议吗?
【解决方案2】:

您可以如下更改虚拟应用程序和目录设置:

/                         site\wwwroot                Application x
/mysite1                  site\mysite1                Application x
/mysite2                  site\mysite2                Application x

当您使用 zipdeploy 或 DevOps 进行部署时,站点名称和目标 URL 如下所示:

更多详情可以参考Deploying multiple virtual directories to a single Azure Website

【讨论】:

  • 谢谢,但 ZipDeploy 和 DevOps 显示的屏幕与 Visual Studio 不同。在这两种情况下,您仍然可以通过不同的方式部署到虚拟目录,但 web.config 文件的问题仍然存在。
猜你喜欢
  • 2022-10-15
  • 2017-01-17
  • 2017-06-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-27
  • 2018-12-21
  • 1970-01-01
  • 2022-07-31
相关资源
最近更新 更多