1

I was able to set up an Apache web server on my home computer, running on Port 80. My forward pathing has been set up so that my public domain takes me to my Apache HTDOCs files. The point, to clarify, is that I was able to host my own web server, so I can host my own website. I am successfully able to show HTML content.

Now, I would like to add NodeJS to this feature, and I am somewhat confused as to how.

Following the answer on this link, I made sure to uncomment the following lines on my httpd file:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

Now I am a little confused on where, in my httpd file, to put this line:

ProxyPass /node http://localhost:8000/

For that matter, I am unsure if this will allow me to access my nodejs externally.

Also, I wonder if I am supposed to be installing NodeJS on my Apache folder, in my case c:/Apache24. If so, what directory would I install that in?

To add, my test node file (named nod.js) contains the following code.

var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Apache!\n');
}).listen(8000);

I run this via node nod on my htdocs. While this works in localhost, it does not display on my external ip.

EDIT: From this example I believe that I have to wrap my ProxyPass inside Virtual Host, something like so:

<VirtualHost *:80>   
     ProxyPass /node http://localhost:8000/ connectiontimeout=5 timeout=30  # optional timeout settings  
</VirtualHost>

This doesn't work, though I assume its within the ballpark of what I'm supposed to be doing.

Community
  • 1
  • 1
Jason Chen
  • 2,487
  • 5
  • 25
  • 44

1 Answers1

2

It does not matter on which directory you run your node server on.
Apache sends the request to node through HTTP, technically, they can be on two different machines (you use localhost, but it can be any other IP address there instead).

The only thing that matters is not the directory, but the port you are using in your node configuration

Nir Levy
  • 12,750
  • 3
  • 21
  • 38
  • Do I also have to forward path my port 8000? – Jason Chen Aug 20 '16 at 15:12
  • I'm a bit confused as to where my error is then. I have an index.html file that runs as soon as I hit my public IP address (for example: http://12.12.12.12.12). Now, when I run `node nod`, my `localhost:8000` shows my node file. But when I go `http://12.12.12.12.12:8000` it does not appear. – Jason Chen Aug 20 '16 at 15:18
  • I assume `12.12.12.12.12` is your apache, right? if so, your proxyPath is set to `/node`, this means it passes requests coming to `http://12.12.12.12.12/node` to `localhost:8000`. try calling this and you should get to your node server – Nir Levy Aug 20 '16 at 15:20
  • Doing `http://12.12/node` does not work, which leads me to believe that I don't know how to set up my ProxyPass. I assume I'm supposed to wrap this inside virtualHost? What would an example code be for something like that? – Jason Chen Aug 20 '16 at 15:50
  • Hey @JasonChen, Did you achieve it? Can you share that sample code here? – JustCurious Oct 20 '21 at 11:06