My goal would be to run Node.js on port 80. The reason being I'm finding node.js has been blocked from certain systems that do not allow traffic from the other port.
It seems that the easiest method to do that is as simple as proxying Apache through Node.js. I've attempted using node-http-proxy to get this done however i haven't had any luck.
The code I'm using is here now:
var util = require('util'), http = require('http'), httpProxy = require('http-proxy') httpProxy.createServer(9000, 'localhost').listen(80) http.createServer(function (req, res) ) res.write('request effectively proxied to: ' + req.url + 'n' + JSON.stringify(req.headers, true, 2)) res.finish() ).listen(9000)
However I keep obtaining the error "Address being used" for port 80. I have to do a problem.
How do you proxy Apache through node.js using node-http-proxy? Will this enable me to operate node.js on port 80? And it is node-http-proxy the easiest method to accomplish this?
What you ought to do is have 2 ip's for that server you're running. Apache has 1 ip certain to port 80 after which node.js has got the other ip certain to port 80.
Using node and it is listen directive has 2 values eg. .listen(80, NODEJS_IP or DNS Title)
I'd not use apache with nodejs as it is not evented. Which means this really is not suggested. I'd really consider using NGINX since it's a far greater pairing with Node.
Your code appears like example code by which you are developing a Node-based proxy from port 80 to port 9000, after which developing a Node-based HTTP server on port 9000. (i.e.
Node:80 -> Node:9000)
You are receiving "address being used" whenever you launch Node because Apache has already been using port 80. If you wish to use Apache to proxy, you have to use Node on the different port (say 9000) and also have Apache listening on port 80 and sending the demands to Node on port 9000. (i.e.
Apache:80 -> Node:9000)
It appears such as the library you are using is perfect for doing the alternative: using Node because the proxy and sending demands to Apache. Within this situation you have to configure Apache to operate on another port than port 80. (i.e.
Node:80 -> Apache:9000).
Do you need to complete
Node:80 -> Apache:9000 or
Apache:9000 -> Node:80, ultimately?
EDIT after comments:
If you wish to do
Apache:80 -> Node:9000, you should use
mod_proxy on Apache and employ the
ProxyPassReverse directives, something similar to
ProxyPass /nodeurls/ http://localhost:9000/ ProxyPassReverse /nodeurls/ http://localhost:9000/
nodeurls may be the group of Web addresses you want for Apache to toward Node.
It's presently not suggested to operate node on port 80, as that needs running node as root.
How attached are you currently to apache? Proxying node through nginx is really a tried and tested solution, by having an nginx-config similar to this:
upstream node_cluster server title foo access_log /var/log/nginx/foo.log location / Submitted-For $proxy_add_x_submitted_for proxy_set_header Host $http_host proxy_pass http://node_cluster/ proxy_redirect off
run your application on the high port 8080 or whatev then
sudo iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 8080
If you're not using ngnix or apache