设置根path以在Azure上提供index.html(IIS Web服务器)
我有一个相当标准的节点应用程序部署到Azure。 默认情况下,对于http:www.example.com/my_path
的请求,Azure会添加一个web.config
xml文件来设置IIS,以便:
a)查看/public
文件夹中是否存在匹配/my_path
的静态文件
b)将所有其他请求路由到nodejs应用程序。
除了根path( http:www.example.com/
)之外,我想要的只是显示public/index.html
,并将path路由到节点应用程序。
我无法做到这一点。 以下是我的web.config
的相关部分:
<!-- 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"/> <!-- WHAT SHOULD THIS NEXT LINE BE TO IGNORE THE BASE PATH FROM THIS RULE TO SEND REQUESTS TO THE NODE APP? --> <add input="{REQUEST_URI}" pattern="^$" negate="True"/> </conditions> <action type="Rewrite" url="server.js"/> </rule>
您可以尝试在web.config
文件中添加和修改以下重写内容:
<rule name="SpecificRedirect" stopProcessing="true"> <match url="/" /> <action type="Rewrite" url="/index.html" /> </rule> <!-- All other URLs are mapped to the node.js site entry point --> <rule name="DynamicContent"> <match url="/api" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="True"/> </conditions> <action type="Rewrite" url="app.js"/> </rule>
如果请求匹配url yourdomain
,它将重写根目录中的index.html
,并停止呈现index.html
请求的rewirte进程由node.js应用程序路由。
另外还configuration了node.js应用程序来处理子模式/api
的请求。