javascript - Hosting multiple Node.JS applications recognizing subdomains with a proxy server -
i trying redirect subdomains specific port on ubuntu aws ec2 virtual server. tried dns , wouldn't work based on following topics, default route using node-http-proxy? , how use node.js http-proxy logging http traffic in computer?, trying create node.js proxy server logging. said mixed bit (i'm new node.js, still learning) , made following script:
var httpproxy = require('http-proxy'); var port = 80; logger = function() { return function (request, response, next) { // run on each request. console.log(json.stringify(request.headers, true, 2)); next(); } } var options = { // list processed top bottom, '.*' go // 'http://localhost:3000' if host header hasn't matched router : { 'dev.domain.com': 'http://localhost:8080', 'beta.domain.com': 'http://localhost:8080', 'status.domain.com': 'http://localhost:9000', 'health.domain.com': 'http://localhost:9000', 'log.domain.com': 'http://localhost:9615', '^.*\.domain\.com': 'http://localhost:8080', '.*': 'http://localhost:3000' } }; // listen port 80 httpproxy.createserver(logger(), options).listen(port); console.log("proxy server started, listening port" + port);
well happens keep getting following error , can't figure out how put work:
$node proxyserver.js proxy server started, listening port80 events.js:72 throw er; // unhandled 'error' event ^ error: listen eacces @ errnoexception (net.js:904:11) @ server._listen2 (net.js:1023:19) @ listen (net.js:1064:10) @ server.listen (net.js:1138:5) @ proxyserver.listen (/home/ubuntu/quantbull-project/node_modules/http-proxy/lib/http-proxy/index.js:130:16) @ object.<anonymous> (/home/ubuntu/quantbull-project/proxyserver.js:28:43) @ module._compile (module.js:456:26) @ object.module._extensions..js (module.js:474:10) @ module.load (module.js:356:32) @ function.module._load (module.js:312:12)
in short i'm trying receive http request on port 80 , if came sub1.domain.com redirected porta , if came frome sub2.domain.com it'll redirected portb same ip adress , both ports open public.
can explain how fix , explain why happens?
port access:
as mentioned previous answer , comments port below 1024 can't opened regular user. can overcome following these instruction:
if
cat /proc/sys/net/ipv4/ip_forward
returns 0 uncommentnet.ipv4.ip_forward
@ file/etc/sysctl.conf
, enable these changes:sudo sysctl -p /etc/sysctl.conf
, if returns 1, skip step;set forwarding port 80 1 desired above 1024 (i.e. port 8080):
sudo iptables -a prerouting -t nat -i eth0 -p tcp --dport 80 -j redirect --to-port 8080;
- open linux firewall allow connections on port 80:
sudo iptables -a input -p tcp -m tcp --sport 80 -j accept
,sudo iptables -a output -p tcp -m tcp --dport 80 -j accept
note: make these changes stick when restarting server may check this out.
http-proxy
's routefeature removed:
after taking care of port access proxy server continued without working, after opening issue seemed routing feature removed because, according nodejitsu inc.:
the feature removed due simplicity. belongs in separate module , not in
http-proxy
http-proxy
responsible proxying bit.
so recommended use http-master
.
using http-master
:
as described in http-master
's readme section, node.js required , need run npm install -g http-master
(may needed run root depending on setup). create config file, i.e. http-master.conf, add our routing details , specific question, config file followed:
{ # detect changes made config file: watchconfig: true, # enable logging stdout: logging: true, # here magic happens, definition of our proxies: ports: { # because defined port 80 redirected port 8080 before, # listen here port, added more, i.e. case of # secure connections trough port 443: 8080 : { proxy: { # proxy traffic monitor subdomains port 9000 'status.domain.com' : 9000, 'health.domain.com' : 9000, # proxy traffic logger subdomains port 9615 'log.domain.com' : 9615, # proxy traffic remaining subdomains port 8000 '*.domain.com' : 8000 }, redirect: { # redirect .net , .org requests .com 'domain.net': 'http://domain.com/[path]', 'domain.org': 'http://domain.com/[path]' } } } }
and done, run with: http-master --config http-master.conf
, our subdomain routing should working fine.
note: if want run proxy server on background recommend using tool forever or pm2, , in case of using pm2 recommend reading this issue.
Comments
Post a Comment