Get a VPS that offers 2 or more IP addresses.
From the WHM cPanel, find the menu item Service Configuration
, select Apache Configuration
and then click on Reserved IPs Editor
.
Tick the IP address you DON'T WANT Apache to listen to, and write it down so you can use it in the next step. Click Save
.
Install Node.js, and create a server like this:
var http = require('http');
var server = http.createServer(function(req, res) {
res.writeHead(200);
res.end('Hello, world!');
});
server.listen(80, '111.111.111.111');
Replacing 111.111.111.111
with the IP address you previously reserved from the WHM cPanel.
Stop wasting your time and never listen to those telling you to use mod_rewrite
to proxy Node.js again.
i think there are countless situations (generally said) potentially involving node.js and apache. I think the use case of the poster is not defined, respectively put in a specific context. Basically his frame is "Running a node.js HTTP server which listens on the default port when there's already an Apache running".
I found this thread through a Google search, looking for a "Method to run Node.js and Apache together", but my frame is that I want to run a small Node.js-based Web-Applet in a subdirectory of an Apache hosted site.
For this particular case I went on using the 'node-fastcgi' npmjs module, and I find it a proper and even well-performing solution to run my Node.js script on the very same IP address AND port as the Apache server.
Also, note the description from the npmjs.org descripton of 'node-fastcgi':
"Create FastCGI applications in node. Near drop-in replacement for node's http module."
This means, effectively that the implementation of the server logic is not any different, so on sites which are not running an Apache the Node.js app can be run standalone using http.createServer() method from Step 4 of this Howto.