Permalink
Browse files

added multi-interface listening

  • Loading branch information...
1 parent 902dedd commit 8eba6019a372150e9f645f7743a5947ec34bf954 Jean-Tiare Le Bigot committed Sep 16, 2011
Showing with 70 additions and 53 deletions.
  1. +2 −2 config.js
  2. +21 −5 proxy.js
  3. +47 −46 readme.txt
View
@@ -10,8 +10,8 @@ var config = {
allow_ip_list: './config/allow_ip_list',
black_list: './config/black_list',
host_filters: './config/hostfilters.js',
- proxy_port: 80,
- proxy_ip: '0.0.0.0'
+ listen:[{ip:'91.121.154.113', port:80},
+ {ip:'2001:41d0:1:db71::1', port:80}]
};
exports.config = config;
View
@@ -141,10 +141,11 @@ function server_cb(request, response) {
else{request.headers.host = host.host;}
//launch new request
- var proxy = http.createClient(host.port || 80, host.host);
- var proxy_request = proxy.request(request.method, request.url, request.headers);
+ try{
+ var proxy = http.createClient(host.port || 80, host.host);
+ var proxy_request = proxy.request(request.method, request.url, request.headers);
- //proxies to FORWARD answer to real client
+ //proxies to FORWARD answer to real client
proxy_request.addListener('response', function(proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk, 'binary');
@@ -155,19 +156,34 @@ function server_cb(request, response) {
response.writeHead(proxy_response.statusCode, proxy_response.headers);
});
+
+
//proxies to SEND request to real server
request.addListener('data', function(chunk) {
proxy_request.write(chunk, 'binary');
});
request.addListener('end', function() {
proxy_request.end();
});
+
+ }catch(err){
+ console.log('ERROR: Caught exception: ' + err);
+ sys.log("Connection to "+host.host+":"+(host.port||80)+" failed");
+ }
}
+//last chance error handler
+process.on('uncaughtException', function (err) {
+ console.log('LAST ERROR: Caught exception: ' + err);
+});
+
+//startup + log
update_blacklist();
update_iplist();
update_hostfilters();
-sys.log("Starting the proxy server on port '" + config.proxy_ip+':'+config.proxy_port);
-http.createServer(server_cb).listen(config.proxy_port, config.proxy_ip);
+config.listen.forEach(function(listen){
+ sys.log("Starting reverse proxy server on port '" + listen.ip+':'+listen.port);
+ http.createServer(server_cb).listen(listen.port, listen.ip);
+});
View
@@ -1,46 +1,47 @@
-Nodejs-proxy is a simple HTTP proxy server written in node.js. It currently
-just proxies all the requests on port 8080.
-
-Nodejs-proxy was written by Peteris Krumins (peter@catonmat.net).
-His blog is at http://www.catonmat.net -- good coders code, great reuse.
-
-------------------------------------------------------------------------------
-
-You'll need node.js to run it. Get it at www.nodejs.org, then compile and
-install it:
-
- $ ./configure
- $ make
- $ make install
-
-Next, run proxy.js through node program:
-
- $ node proxy.js
-
-And that's it!
-
-I have also added ip-based access control and by default the proxy will
-deny all IPs. To add a new ip, just echo it to 'allow_ip_list' file:
-
- $ echo '1.2.3.4' >> config/allow_ip_list
-
-And you don't need to restart the server, it will see the changes and update
-itself.
-
-You can also block hosts based on a regex pattern, to do that, echo the hosts
-you don't wish the proxy to serve to 'black_list' file:
-
- $ echo 'facebook.com' >> config/black_list
-
-
-More features coming later!
-
-
-------------------------------------------------------------------------------
-
-Happy proxying!
-
-Sincerely,
-Peteris Krumins
-http://www.catonmat.net
-
+Nodejs-proxy is a simple HTTP reverse proxy server written in node.js. It currently
+allows some mid-complexity to handle the reverse proxy magic take place.
+
+Nodejs-proxy was written by Peteris Krumins (peter@catonmat.net).
+His blog is at http://www.catonmat.net -- good coders code, great reuse.
+
+------------------------------------------------------------------------------
+
+You'll need node.js to run it. Get it at www.nodejs.org, then compile and
+install it:
+
+ $ ./configure
+ $ make
+ $ make install
+
+Next, run proxy.js through node program:
+
+ $ node proxy.js
+
+And that's it!
+
+I have also added ip-based access control. As long as no ip is explicitly denied,
+all will be allowed. If you need a specic access list just echo it to
+'allow_ip_list' file:
+
+ $ echo '1.2.3.4' >> config/allow_ip_list
+
+And you don't need to restart the server, it will see the changes and update
+itself.
+
+You can also block hosts based on a regex pattern, to do that, echo the hosts
+you don't wish the proxy to serve to 'black_list' file:
+
+ $ echo 'facebook.com' >> config/black_list
+
+
+More features coming later!
+
+
+------------------------------------------------------------------------------
+
+Happy proxying!
+
+Sincerely,
+Peteris Krumins
+http://www.catonmat.net
+

0 comments on commit 8eba601

Please sign in to comment.