使用节点和Azure WebApp自定义静态错误页面
我正在使用Azure WebApps构build一个静态页面和节点网站的混合体,我想要一个自定义的404页面,但我不能使其工作。 大多数网站是静态的,但我有一些需要服务器代码的路线。 我的web.config如下所示:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <httpProtocol> <customHeaders> <remove name="X-Powered-By"/> <add name="x-dns-prefetch-control" value="on"/> </customHeaders> </httpProtocol> <handlers> <add name="iisnode" path="src/server/index.js" verb="*" modules="iisnode"/> </handlers> <rewrite> <rules> <rule name="static"> <match url="(?!dynamicroute).*$" ignoreCase="true"/> <action type="Rewrite" url="dist{REQUEST_URI}"/> </rule> <rule name="dynamic"> <match url="(?:dynamicroute)(.*)$" ignoreCase="true"/> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> </conditions> <action type="Rewrite" url="src/server/index.js"/> </rule> </rules> </rewrite> <!-- Make sure error responses are left untouched --> <!--<httpErrors existingResponse="PassThrough"/>--> <httpErrors errorMode="Custom" defaultResponseMode="File" existingResponse="PassThrough"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="~/404.html" responseMode="File" /> </httpErrors> </system.webServer> </configuration>
我尝试了httpErrors
不同变体, path
值, responseMode
,去掉existingResponse="PassThrough"
等,但我不能使它的工作。
直接访问/404.html
作品。 访问不存在的url时,服务器返回404错误,而不是我想要的自定义。 我究竟做错了什么?
我知道我可以处理节点上的所有事情,但是如果可能的话,我想避免这种情况。
我能够得到自定义404.html
页面与以下web.config
文件和Azure应用服务上的expressjs应用程序。 你可以把它作为参考。
web.config中
<?xml version="1.0" encoding="utf-8"?> <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> <httpErrors errorMode="Custom" defaultResponseMode="ExecuteURL"> <remove statusCode="404" subStatusCode="-1" /> <error statusCode="404" path="/public/404.html" responseMode="ExecuteURL" /> </httpErrors> <iisnode watchedFiles="web.config;*.js" debuggingEnabled="false" /> </system.webServer> </configuration>
文件夹结构
当我访问任何文件不存在时,我得到了404页面显示。
- 端口在IISNode上运行的Azure Node.js应用程序中未定义
- 如何通过Azure网站上的Node.js应用程序将大文件stream上传到Azure Blob存储?
- Express应用程序在azure色上投掷500个
- 天青nodejs网站/ webapp支持JWT令牌生成和validation的encryptionalgorithm
- lwip在azure web应用程序中的node-gyp重build问题:致命错误C1083:无法打开包含文件:'nan.h':没有这样的文件或目录
- 在azure节点js web应用程序上找不到字体.woff 404
- Grunt无法在Azure网站上运行
- 无法连接到数据库 – EADDRNOTAVAIL
- Azure Web App:激活应用程序日志超过12小时