如何用IIS成功运行节点服务器?

How to successfully run node server with IIS?

所以我有一个 Web 应用程序 ISS-10,运行 在 wwww.mymindmapper.com 上监听 port:80。我有两个简单的页面 (login.html & register.html)。这是它的样子:https://imgur.com/a/gb9KAsj

我的主要 objective 是尝试弄清楚如何使用我在 port: 80 上的 IIS 上的 webApp 创建 Node JS 服务器 (port: 81)。这是我的 app.js 文件:

//USE `nodemon scripts/server.js` on Terminal to refresh Node Server on File Save.
//USE 'pm2 start scripts/server.js' on Terminal to start pm2 for IIS ??????????????????

//Import Node JS modules
const express = require("express");
const morgan = require("morgan"); 
const mysql = require("mysql");

//Create a new instance of express()
const app = express();

//GET INFORMATION ABOUT THE SERVER REQUESTS (OS, Browser, time, Internal Errors, Status Codes)
app.use(morgan('short')); //'short', 'combined'

//Require files from folder public     (THIS CONTAINS ALL .html files inc. login.html and register.html)
app.use(express.static('./public'));

//Listen on PORT:80 with a callback function
app.listen(81, ()=>{
    console.log("Server running on port 81");
});

请注意,当我通过终端在 Visual Studio 代码上发出请求时,一切都按预期进行。数据可以是 added/deleted 来自我的数据库。 (我使用 XAMPP - Apache 监听 port:80 而 mMySQL 监听 port:3306)。

我在某处读到这可以通过在 IIS 上使用 Reverse Proxy 来解决。但是,这似乎不起作用。另外当我设置了reverse-proxy 刷新页面的时候出现了下面的错误。

哥们,出站规则不用设置了。您编写的上述设置足以将 IIS 请求转发到节点服务器。

在应用程序请求路由中,启用代理功能。

Index.js

var express=require('express');
var app=express();
app.get('/',function(req,res){
    res.send('Hello World');
})
app.listen(3000,function(){
    console.log("Example app listening on port 3000!");
})

我的 IIS 站点绑定。

结果。

添加反向代理规则会生成一个包含以下内容的 webconfig 文件。

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:3000/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

此外,如果您在server farms中创建了服务器场,请将其删除或添加本地IP作为默认服务器。否则会出现无法连接服务器的错误
如果问题仍然存在,请随时告诉我。