How to successfully run node server with IIS?

一曲冷凌霜 提交于 2021-01-29 02:08:07

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/62391237/how-to-successfully-run-node-server-with-iis

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!