我们在Azure上有一个nodeJS webapp,它运行正常。
流式传输服务器日志时,每次加载页面时,所有资源(图像,css等)上都会出现一堆404错误。但是页面仍可以正确显示。
详细错误显示如下:
Requested URL https://[myappname]:80/settings.png
Physical Path D:\home\site\wwwroot\settings.png
Logon Method Anonymous
Logon User Anonymous
请求的URL显然是错误的,应该为https://[myappname].azurewebsites.net/settings.png,它是给定资源的公共URL,并且可以正常工作。 此问题将加载大量日志,因此目前无法使用Web Server日志。
谢谢!
编辑:与this problem不同,我的页面正确加载并且资源文件可用。
已解决 :我已将以下处理程序添加到我的web.config中:
<add name="UrlRoutingModule-4.0" path="*" verb="*" type="System.Web.Routing.UrlRoutingModule" preCondition="" />
答案 0 :(得分:0)
我相信您需要在web.config中为静态文件内容配置一个规则集。
<rule name="StaticContent">
<action type="Rewrite" url="public{REQUEST_URI}"/>
</rule>
在Azure Web Apps上运行的Node.js应用程序通过IISNode托管在IIS上。因此,需要一个web.config文件在IIS上配置您的应用程序。如果您通过Continuous Deployment将应用程序部署到Azure App Service,则Azure将自动生成web.config文件。或者,您可以从此处下载文件。
我发布默认的web.config仅供参考”
<?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>
希望有帮助。
答案 1 :(得分:0)
感谢您的回答。
我有几乎相同的web.config,是自动生成的。您指出的规则略有不同:
<rule name="StaticContent">
<action type="Rewrite" url="public{PATH_INFO}"/>
</rule>
我的服务器代码包括:
app.use(express.static(path.join(__dirname, 'public')));