Italy's daily coronavirus death toll and new cases fall

Hosting multiple Express (node.js) apps on port 80

, In the last days, i was trying to find a solution hosting multiple Express apps on my vServer the same Server.
Starting with Apache and mod_proxy, i ended up with a plain node solution, which i really like.

Let’s take a quick look on some different approaches out there:
—1—
Using apache on port 80 as a proxy
1ProxyPass /nodeurls/ http://localhost:9000/
2ProxyPassReverse /nodeurls/ http://localhost:9000/
via stackoverflow
— no websockets
++ probably the easiest way to integrate with your running AMPP-stack
—2—
Using a node.js app on port 80 as a Wrapper for other node apps.
1express.createServer()
2  .use(express.vhost('hostname1.com', require('/path/to/hostname1').app)
3  .use(express.vhost('hostname2.com', require('/path/to/hostname2').app)
4.listen(80)
via stackoverflow
++ you can use websockets on port 80
— apps crash/restart/stop globally
–what about your apache or the like?
—3—
Using node.js with node-http-proxy on port 80
1var http = require('http')
2, httpProxy = require('http-proxy');
3 
4httpProxy.createServer({
5  hostnameOnly: true,
6  router: {
7    //web-development.cc
8    'www.my-domain.com': '127.0.0.1:3001',
9    'www.my-other-domain.de' : '127.0.0.1:3002'
10  }
11}).listen(80);
++ proxy websockets to any port
— you might need to move your old web server to another port
The really cool thing about using node-http-proxy is its capability of proxying websockets.
So you can have your apps running independtly on different ports while serving everything to the user over port 80 and use stuff like socket.io.
Since i’m new to node.js and miles away from beeing a admin, any feedback is highly appreciated :)

Comments