【问题标题】:How to successfully run node server with IIS?如何使用 IIS 成功运行节点服务器?
【发布时间】:2020-10-05 01:01:57
【问题描述】:

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

我的主要目标是尝试找出如何在位于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 Code 上的终端发出请求时,一切正常。可以从我的数据库中添加/删除数据。 (我使用 XAMPP - Apache 监听 port:80 而 mMySQL 监听 port:3306)。

我在某处读到,这可以通过 IIS 上的 Reverse Proxy 来解决。但是,这似乎不起作用。此外,当我进行反向代理配置时,刷新页面时会出现以下错误。

【问题讨论】:

  • 我有一个在 IIS 上运行 NodeJS 的站点,我们使用 IIS Node 来管理它:github.com/Azure/iisnode 我没有设置站点,所以我不是 100% 的配置。
  • 在这个问题的各个方面,您都声称 IIS 在端口 80 上运行,而 Apache 在端口 80 上运行。它是哪一个?您在处理多台计算机吗?您是否在它们两个上都运行过您的 Node 应用程序?
  • @AdrianJ.Moreno,谢谢。我去看看。
  • @Quentin 感谢您的回复。不,只有一台电脑。我不确定这是如何工作的。当我去localhost:80 XAMPP 欢迎页面加载,当我尝试mymindmapper.com 它加载我的webApplication。这也可以同时工作。
  • @AdrianJ.Moreno 我刚刚在 IIS 中检查了我的 WebApp 上的模块,但 iisnode 不存在。这是我想要包含的内容吗?

标签: javascript node.js port reverse-proxy iis-10


【解决方案1】:

哥们,不需要设置出站规则。您编写的上述设置足以将 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作为默认服务器。否则会出现无法连接服务器的错误。
如果问题仍然存在,请随时告诉我。

【讨论】:

  • 感谢您的回复。我发现没有安装 Application Request Routing 3.0 扩展,所以我已经修复了。我已更改我的 app.js 以监听 port:3000,并创建了一个没有入站的新反向代理(我已删除其他 2 个)。当我安装应用程序请求路由时,代理功能已经启用,并将绑定更改为 ALL UNASIGNED,它运行良好。你是上帝,我的朋友。 :D
猜你喜欢
  • 2015-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-09-03
  • 2020-02-23
  • 2013-12-11
  • 2017-05-09
  • 1970-01-01
相关资源
最近更新 更多