大佬教程收集整理的这篇文章主要介绍了如何在 web.config 中编写规则以通过更改域在子文件夹内启动另一个节点应用程序,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个在 Azure 中运行的 Web 应用程序。我正在部署的文件夹由:
-testapp
node_modules
index.Js
package.Json
package-lock.Json
web.config
-testapp2
node_modules
index.Js
package.Json
package-lock.Json
./index.Js
和 ./testapp2/index.Js
中的源代码几乎相同,只是输出不同
const express = require("express");
const app = express();
app.get("/",(_,res)=>{
res.status(200).send("Welcome to TestApp"); // testapp2: Welcome to TestApp2
});
app.get("/test",res)=>{
res.status(200).send("TestApp TestPath"); //testapp2: TestApp2 TestPath
});
const PORT = process.env.PORT || 1337;
app.Listen(PORT,() => console.log(`Listening to http://localhost:${PORT}`));
我的目标是转到域 example.com/
,然后从主文件夹启动 index.Js
。当我转到 example.com/testapp2
时,它会启动 ./testapp2/index.Js
并且我看到来自子文件夹的欢迎消息:
"Welcome to TestApp" when I go to "/" it works
"TestApp TestPath" when I go to "/test" it works
"Welcome to TestApp2" when I go to "/testapp2" instead I get "CAnnot GET /testapp2"
"TestApp2 TestPath" when I go to "/testapp2/test" instead I get "CAnnot GET /testapp2/test"
我认为这个问题可以通过更改 web.config 文件来解决:
<?xml version="1.0" enCoding="utf-8"?>
<configuration>
<system.webServer>
<webSocket enabled="false" />
<handlers>
<add name="IIsnode" path="index.Js" verb="*" modules="IIsnode"/>
</handlers>
<rewrite>
<rules>
<rule name="NodeInspector" patternSyntax="ECMAScript" stopProcessing="true">
<match url="^index.Js\/deBUG[\/]?" />
</rule>
<rule name="StaticContent">
<action type="Rewrite" url="public{requEST_URI}"/>
</rule>
<!-- ------------------------This is the ruled I created-------------------------- -->
<rule name="TestApp2Content" stopProcessing="true">
<match url="^testapp2"/>
<conditions>
<add input="{requEST_filename}" matchType="IsDirectory" negate="True"/>
</conditions>
<action type="Rewrite" url="testapp2/index.Js"/>
</rule>
<!-- ----------------------------------------------------------------------------- -->
<rule name="DynamicContent">
<conditions>
<add input="{requEST_filename}" matchType="Isfile" negate="True"/>
</conditions>
<action type="Rewrite" url="index.Js"/>
</rule>
</rules>
</rewrite>
<security>
<requestfiltering>
<hIDdenSegments>
<remove segment="bin"/>
</hIDdenSegments>
</requestfiltering>
</security>
<httpErrors exisTingResponse="Passthrough" />
</system.webServer>
</configuration>
但我仍然收到无法获取错误。我想知道我做错了什么。我是该配置文件和重写规则的初学者,这就是为什么我非常确定存在错误但我不知道如何正确编写规则。我做错了什么?
非常感谢您的时间!
testapp 和 testapp2 应该是两个不同的应用程序,在 Azure WebApps 上部署多个应用程序的最佳方式是为你的 Azure Web 应用程序设置虚拟应用程序和应用程序设置目录。
以上是大佬教程为你收集整理的如何在 web.config 中编写规则以通过更改域在子文件夹内启动另一个节点应用程序全部内容,希望文章能够帮你解决如何在 web.config 中编写规则以通过更改域在子文件夹内启动另一个节点应用程序所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。