虽然我的应用在本地运行良好,但我很难将其部署到Azure Web App。
申请结构如下:
在拼接其他来源的花絮之后,我对web.config的最佳猜测如下:
<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>
<rule name="Static files" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- Core application files -->
<add input="{REQUEST_URI}" pattern="assets/" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="views/" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{REQUEST_URI}" />
</rule>
<rule name="Express.js API">
<match url="api/*" />
<action type="Rewrite" url="app.js"/>
</rule>
<rule name="Angular">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
不幸的是,在发布到Azure之后,虽然加载了大多数assets /和index.html文件(在浏览器调试窗口中查看),但我得到了一个&#34;无法加载资源:服务器响应状态500(内部服务器错误)&#34;在/assets/angular/app.js。
可能导致此问题的原因是什么?此外,是否有在Azure上部署MEAN应用程序的标准?这种MEAN应用程序是否有标准的web.config?
答案 0 :(得分:0)
在Azure中支持MEAN应用程序的技巧归结为以下几点:
在server.js中:
// Within server.js - make sure we're listening on the proper port
server.listen(process.env.PORT, function () {
logger.info('Web server listening on port ' + process.env.PORT)
});
然后是web.config:
<handlers>
<!-- Indicates that the app.js file is a node.js site to be handled by the iisnode module -->
<add name="iisnode" path="server.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="^server.js\/debug[\/]?" />
</rule>
<!-- For static files, redirect to the URI -->
<rule name="Static files" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<!-- Any directory/file in the assets/ or views/ directory -->
<add input="{REQUEST_URI}" pattern="assets\/" ignoreCase="true" />
<add input="{REQUEST_URI}" pattern="views\/" ignoreCase="true" />
</conditions>
<action type="Rewrite" url="{REQUEST_URI}"/>
</rule>
<!-- For Express.js middleware API, if using api/ prefix, then use server.js -->
<rule name="Express.js URIs">
<match url="api/*" />
<action type="Rewrite" url="server.js" />
</rule>
<!-- For Angular.js URIs, rewrite to the index.html file -->
<rule name="Angular">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="index.html" />
</rule>
</rules>
</rewrite>
对于那些被类似问题困扰的人,我可以推荐: