admin管理员组文章数量:1393053
I am using IIS as a reverse proxy to forward requests to my Node.js API running on localhost (port 3000). However, only the root route (ppas_app/) works, and any other endpoint like ppas_app/api/test or ppas_app/api/users returns 404 Not Found.
• IIS as Reverse Proxy
• Node.js API running on port 3000
• ARR (Application Request Routing) and URL Rewrite enabled
• IIS is configured to forward all requests to http://localhost:3000
Issue Details:
- Accessing ✅ Works as expected
- Accessing ❌ Returns 404
Not Found 3. Accessing http://localhost:3000/api/test ✅ Works directly on Node.js 4. No errors in IIS logs, but the API routes don’t seem to be forwarded properly.
**my web.config : **
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\node.log" startupTimeLimit="20" processPath="D:\api\node.exe" arguments=".\app.js">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:3000/(.*)" />
<action type="Rewrite" value="http{R:1}://"www.example"/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Node.js Api sample test:
const port = process.env.PORT || 3000;
app.get('/', function(req, res){
return res.status(200).send('First');
})
app.get('/api/test', function(req, res){
return res.status(200).send('First Server');
})
app.get('/nodetest/api/test', function(req, res){
return res.status(200).send('as an IIS application');
})
app.listen(port, () =>{
console.log(`Server is listening to ${port}.....`);
})
I am using IIS as a reverse proxy to forward requests to my Node.js API running on localhost (port 3000). However, only the root route (ppas_app/) works, and any other endpoint like ppas_app/api/test or ppas_app/api/users returns 404 Not Found.
• IIS as Reverse Proxy
• Node.js API running on port 3000
• ARR (Application Request Routing) and URL Rewrite enabled
• IIS is configured to forward all requests to http://localhost:3000
Issue Details:
- Accessing http://www.example/spintas_app ✅ Works as expected
- Accessing http://www.example/spintas_app/api/test ❌ Returns 404
Not Found 3. Accessing http://localhost:3000/api/test ✅ Works directly on Node.js 4. No errors in IIS logs, but the API routes don’t seem to be forwarded properly.
**my web.config : **
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" requireAccess="Script" />
</handlers>
<httpPlatform stdoutLogEnabled="true" stdoutLogFile=".\node.log" startupTimeLimit="20" processPath="D:\api\node.exe" arguments=".\app.js">
<environmentVariables>
<environmentVariable name="PORT" value="%HTTP_PLATFORM_PORT%" />
<environmentVariable name="NODE_ENV" value="Production" />
</environmentVariables>
</httpPlatform>
<rewrite>
<rules>
<rule name="ReverseProxyInboundRule1" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="http://localhost:3000/{R:1}" />
</rule>
</rules>
<outboundRules>
<rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
<match filterByTags="A, Form, Img" pattern="^http(s)?://localhost:3000/(.*)" />
<action type="Rewrite" value="http{R:1}://"www.example"/{R:2}" />
</rule>
<preConditions>
<preCondition name="ResponseIsHtml1">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
</preConditions>
</outboundRules>
</rewrite>
</system.webServer>
</configuration>
Node.js Api sample test:
const port = process.env.PORT || 3000;
app.get('/', function(req, res){
return res.status(200).send('First');
})
app.get('/api/test', function(req, res){
return res.status(200).send('First Server');
})
app.get('/nodetest/api/test', function(req, res){
return res.status(200).send('as an IIS application');
})
app.listen(port, () =>{
console.log(`Server is listening to ${port}.....`);
})
Share
Improve this question
edited Mar 17 at 10:11
VLAZ
29.1k9 gold badges63 silver badges84 bronze badges
asked Mar 15 at 9:13
Syahrul IzwanSyahrul Izwan
1
1
- i have question if you are using the http handle with iis to serve the application of node js from iis may i know why you have set the reverse proxy ? is the hosted app is different from you have set the reverse proxy – Jalpa Panchal Commented Mar 17 at 2:36
1 Answer
Reset to default 0You could try to add the base path in your node js. as your node js path is design to handle the request with the /api/test or /api/users but right now your requesting with the ppas_app/api/users which node js does not understnd.
or else you can set iis url rewrite rule to only fowrad the request of the sub application to the node js app something like below:
Insted of:
<match url="(.*)" />
use:
<match url="^ppas_app/(.*)" />
本文标签:
版权声明:本文标题:node.js - IIS Reverse Proxy with ARR & URL Rewrite Only Works for Root Route (), Other Routes Fail - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744619744a2615948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论