title: How to configure web.config for multiple virtual applications in Azure App Service?
body: <p>I am trying to have multiple Node.js applications working in parallel in the same Azure App Service instance. I tried making a virtual application per Node.js app but I constantly get a server error (code 500). I use ZipDeploy or Azure DevOps to deploy my applications.</p>
  
  <p>I suspect the problem might be that the <i>web.config</i> files associated with my applications is incorrect.</p>
  
  <p>Here are some details on my setup:</p>
  
  <p>In the <i>Application settings</i> menu of my App Service instance, I went to the <i>Virtual applications and directories</i> settings and put the following:</p>
  
  <pre><code>/                         site\wwwroot                        Application x
  /mysite1                  site\wwwroot\mysite1                Application x
  /mysite2                  site\wwwroot\mysite2                Application x
  </code></pre>
  
  <p>My <i>wwwroot</i> directory looks as follows. To make sure the problem doesn't come from the code itself, I used the same Node.js application for all three:</p>
  
  <pre><code>index.html
  server.js
  scripts
  web.config (*)
  ----- mysite1
        |----- index.html
        |----- server.js
        |----- scripts
        |----- web.config (**)
  ----- mysite2
        |----- index.html
        |----- server.js
        |----- scripts
        |----- web.config (***)
  </code></pre>
  
  <p>I use the default web.config file (<a href="https://github.com/projectkudu/kudu/wiki/Using-a-custom-web.config-for-Node-apps" rel="nofollow noreferrer">provided by Kudu</a>) for the three of them:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;configuration&gt;
    &lt;system.webServer&gt;
  
      &lt;webSocket enabled="false" /&gt;
      &lt;handlers&gt;
        &lt;add name="iisnode" path="server.js" verb="*" modules="iisnode"/&gt;
      &lt;/handlers&gt;
      &lt;rewrite&gt;
        &lt;rules&gt;
          &lt;rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true"&gt;
            &lt;match url="^server.js\/debug[\/]?" /&gt;
          &lt;/rule&gt;
  
          &lt;rule name="StaticContent"&gt;
            &lt;action type="Rewrite" url="public{REQUEST_URI}"/&gt;
          &lt;/rule&gt;
  
          &lt;rule name="DynamicContent"&gt;
            &lt;conditions&gt;
              &lt;add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/&gt;
            &lt;/conditions&gt;
            &lt;action type="Rewrite" url="server.js"/&gt;
          &lt;/rule&gt;
        &lt;/rules&gt;
      &lt;/rewrite&gt;
  
      &lt;security&gt;
        &lt;requestFiltering&gt;
          &lt;hiddenSegments&gt;
            &lt;remove segment="bin"/&gt;
          &lt;/hiddenSegments&gt;
        &lt;/requestFiltering&gt;
      &lt;/security&gt;
  
      &lt;httpErrors existingResponse="PassThrough" /&gt;
  
    &lt;/system.webServer&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>Using this configuration, I can reach <i><a href="https://myappservice.azurewebsites.net/" rel="nofollow noreferrer">https://myappservice.azurewebsites.net/</a></i> without issue but <i><a href="https://myappservice.azurewebsites.net/mysite1" rel="nofollow noreferrer">https://myappservice.azurewebsites.net/mysite1</a></i> only returns a server error.</p>
  
  <p>I tried taking off the handlers from the <i>web.config</i> files in subdirectories (** and ***) as instructed in similar questions but to no avail.</p>
  
  <p>What is the correct configuration for these three files? I suppose the rewrite rules need to be adjusted but I am unsure what is the exact expected value for each.</p>