如何使用 IIS 成功运行节点服务器? [英] How to successfully run node server with IIS?

查看:64
本文介绍了如何使用 IIS 成功运行节点服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

哥们,不用设置出站规则了.您编写的上述设置足以将 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("示例应用程序监听端口 3000!");})

我的 IIS 站点绑定.

结果.

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

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

So I have a web application with ISS-10, running on wwww.mymindmapper.com and listening on port:80. I have two simple pages (login.html & register.html). Here is what it looks like: https://imgur.com/a/gb9KAsj

My main objective is to try and figure out how to create a Node JS server (port: 81) with my webApp on IIS that is on port: 80. Here is my app.js file:

//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");
});

Please note that when i make requests through terminal on Visual Studio Code, everything works as expected. Data can be added/deleted from my database. (I use XAMPP - Apache listens on port:80 and mMySQL listens on port:3306).

I have read somewhere that this can be solved with a Reverse Proxy on IIS. However this doesn't seems to work. Also when the reverse-proxy configuration is made the following error occurs when i refresh the page.

解决方案

Buddy, there is no need to set up the outbound rules. the above settings you wrote is enough to forward the IIS requests to node server.

In Application Request Routing, enable proxy functionality.

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!");
})

My IIS site bindings.

Result.

Adding the Reverse Proxy Rules generates a webconfig file with below content.

<?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>

Besides, if you have created a server farm in the server farms, please remove it or add the local IP as the default server. Otherwise, there will be an error that cannot connect to the server.
Feel free to let me know if the problem still exists.

这篇关于如何使用 IIS 成功运行节点服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆