Node.JS not serving port 80 on IIS - node.js

I stopped IIS on Windows Server 2019 completely, and Im serving my NodeJS app on port 80 as follows:
const express= require('express');
const app=express();
...
...
...
const hostname = '0.0.0.0';
const port = 80;
app.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
But Node is not serving remotely. It works with localhost:80
Ive set hostname = '0.0.0.0' based on an answer I've found here at StackOverflow. The server's public IP doesn't work either.
When turning IIS on and setting up the site, I can see an index.html file just fine, so port 80 works.
Is it a server issue, or a node.js issue?
Im starting node with
node index.js
Thanks.

For those facing this issue, I fixed it up as Tadman recommended on the above comments: configuring IIS for forwarding (by installing the Application Request Routing and the URL rewrite extensions to IIS).
Node.js also worked when creating a new rule at Windows firewall for enabling port 80. The default rule at the firewall for port 80 will work only with IIS, not with Node.js.
As for the extensions mentioned above, here is a good instructive about how to install and setup:
https://dev.to/petereysermans/hosting-a-node-js-application-on-windows-with-iis-as-reverse-proxy-397b

Related

Enabling HTTPS port on a nodeJS application hosted on cPanel

I have an nodeJS application using express hosted using cPanel on CENTOS 7.9 kvm. Just struggling to get it running with HTTPS inside the nodeJS app.
let httpServer = http.createServer(app).listen(port);
const httpsServer = https.createServer(sslOptions, app);
httpsServer.listen(443, () => {
console.log("HTTPS Server started")
});
The configuration works, but when start with pm2 it shows another process is listening to the SSL port which is "httpd", when I pause "httpd" the application works fine but the process restarts itself and knocks the application offline. Is there anyway to run the application alongside this process? I've looked into port forwarding but not sure how to go about with cPanel.
Thanks

How to access meteor app from outside without passing through NginX?

I am hosting a meteor app on an Ubunu Linux machine. The app is listening on port 3000. If I use a webserver, like NginX and forwards the HTTP requests from port 80 to 3000 I can browse to the server from the outside and see reach the app. However, when I try to access the app directly at port 3000, i.e. browse http://myhost:3000 it just tries to connect and nothing happens.
I have made sure that all firewalls are down and that the app is listening on all interfaces, i.e. 0.0.0.0:3000, so that is not the issue.
To verify that port was actually reachable, I created a simple node js webserver:
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('Hello World!');
res.end();
}).listen(3000);
Now browsing to the the sever, I can see "Hello World!". So obviously this works so why I can not reach meteor has nothing to do with firewalls or unopened ports.
Thus it seems that there is something strange when trying to access a meteor app directly at port 3000. But why? I use the following environment variables:
export MONGO_URL=mongodb://localhost:27017/meteor
export HOST=myhost
export PORT=3000
export ROOT_URL=http://myhost
So what am I missing? Ports are open and I can see that the node process instance is listening on port 3000 when I run netstat -tulpan
I was using the force-ssl meteor package which makes a redirect back to the ROOT_URL without port number. So solution is to remove the package to make it work with a custom port.
I was discussing the solution on the meteor forum where I got the solution:
https://forums.meteor.com/t/can-not-access-meteor-app-without-passing-through-nginx-server/40739/11

Node.js socket app on openshift

I'm trying to deploy a simple node.js socket app on OpenShift.
First I tried setting up the listener as:
var server = net.createServer(newSocket); //newSocket is a listener method
var port = 8888;
server.listen(port);
and this causes:
Error: listen EACCES
Then I researched a bit and learned that you need to listen using OPENSHIFT_NODEJS properties and set the listener like this:
var server = net.createServer(newSocket);
var ipaddr = process.env.OPENSHIFT_NODEJS_IP || "127.0.0.1";
var port = process.env.OPENSHIFT_NODEJS_PORT || 8888;
server.listen(port, ipaddr);
Now the app is started at: 127.6.253.1:8080 - however when I try to telnet it using my OpenShift app url and 8080 I get server timeout.
If you have experience with the similar situation let me know.
The code of the app I'm trying to make it work on OpenShift is at https://github.com/denimf/NodeChat
The internal port for the OpenShift app is 8080, but it is exposed externally on port 80 at the URL specified in your control panel. You can also see the app URL in the console by doing:
echo $OPENSHIFT_APP_DNS
Most of the node.js web hosting services don't support socket listener. I solved my problem by hosting the Node app on a dedicated virtual machine.

How to run "Deployd" on port 80 instead of port 5000 in webserver.

Im running a website with "deployd" and I having issues to change my applicaiton of running on port 5000 to port 80. What I want to do is instead of having "mydomain.com:5000", I just want to have "mydomain.com"
Thank you.
According to these docs of the internal API:
http://docs.deployd.com/docs/developing-modules/internal-api/server.html
You can pass in an options object when creating the server. So something like this should work
var deployd = require('deployd'),
options = {
port : 80
},
server = deployd(options);

EC2 hosted Node.js application - can't remotely connect to port

Update: Turns out the only problem was that I was behind a firewall that blocked some ports, but not 8000.
Edit: TL;DR: can't connect to port 9000 remotely, but port 8000 is ok and I don't know why :(
I've got this node.js application that's running on port 8000 and another one (http-proxy) running on port 9000.
Running them on my machine is fine, but I have some problems when I put them up on a server (EC2 instance - I did open the ports in the web console security group[1]). The application works fine, but I can't connect to the proxy from outside. I tried to $ telnet localhost 9000 on the server and it connects, so I guess that's a good sign.
Another thing that I have noticed is that if I try to run the applications separately, I get the same results, i.e.: 8000 - OK, 9000 - NOTOK :<.
However, if I change the port the proxy uses from 9000 to 8000, it works. And if I switch the ports, i.e. application:9000 and proxy:8000, I can connect to the proxy, but not to the application. I have also tried other numbers, but that wouldn't fix it either.
I guess there's something really stupid that has nothing to do with the application itself and that I'm missing, but I can't put my finger on it, so does anyone have any idea why this setup doesn't work?
server.js
var express = require('express.io');
var app = module.exports = express();
require('./proxy');
app.http().io();
app.listen(8000);
// ...
proxy.js
var httpProxy = require('http-proxy');
var url = require('url');
httpProxy.createServer(function(req, res, proxy) {
// ...
proxy.proxyRequest(req, res, {
host: destination.host,
port: 80
});
}).listen(9000);
$ netstat -pln | grep node output
tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN 1487/node
tcp 0 0 0.0.0.0:8000 0.0.0.0:* LISTEN 1487/node
Security group rules
It turned out that the problem was not at all related to the application or the EC2 instance setup.
The network I was in while testing this was blocking some ports. This is why when moving the proxy to port 8000 it was working fine, but on 9000 or any other random ones that I tried it wasn't. D'oh!

Resources