javascriptnode.jsportreverse-proxyiis-10

How to successfully run node server with IIS?


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://i.sstatic.net/hLLfU.jpg

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.

Reverse proxy configuration

enter image description here


Solution

  • 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.
    enter image description here
    In Application Request Routing, enable proxy functionality.
    enter image description here
    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.
    enter image description here
    Result.
    enter image description here
    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.