we have a nodeJS webapp at Azure which works fine.

When streaming the server logs, any time I load a page, I get a bunch of 404 errors on all resources (images, css, etc..). Yet the page shows up properly.

Detailed errors show the following:

Requested URL      https://[myappname]:80/settings.png
Physical Path      D:\home\site\wwwroot\settings.png
Logon Method       Anonymous
Logon User     Anonymous

The requested URL is clearly wrong, it should be https://[myappname].azurewebsites.net/settings.png, which is the public URL for the given resources, and works fine. This problem loads huge amounts of logs and makes it impossible to use Web Server logs for now.

thank you!

Edit: unlike this problem, my pages load properly and the resource files are well available.

Solved I have added the following handler to my web.config :

<add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition="" />

2 Answers

0
MohitVerma-MSFT On

I believe you need to configure a ruleset in your web.config for static file content.

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

Node.js applications running on Azure Web Apps are hosted on IIS via IISNode. So, a web.config file is required to config your application on IIS. If you deploy your app to Azure App Service via Continuous Deployment, the web.config file will be automatically generated by Azure. Or you can download the file from here.

I am posting default web.config just for your reference"

<?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 app.js file is a node.js site to be handled by the iisnode module -->
               <add name="iisnode" path="app.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="^app.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{REQUEST_URI}"/>
                    </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="app.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

               To debug your node.js application:
                 * set the debuggingEnabled option to "true"
                 * enable web sockets from the portal at https://manage.windowsazure.com/#Workspaces/WebsiteExtension/Website/aarontestnode/configure
                 * browse to https://aarontestnode.azurewebsites.net/app.js/debug/

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

Hope it helps.

0
Cédric Mallet On

thanks for your answer.

I have nearly the same web.config, automatically generated. There is just a slight difference in the rule you pointed :

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

My server code includes this:

app.use(express.static(path.join(__dirname, 'public')));