nproxy 基于Nodejs的Proxy

npr

A nodejs proxy server.

Supports TCP in proxy mode, HTTP and Websocket in router mode.

Installation

sudo npm install npr -g

Startup

  • Start the proxy server with default configuration 'proxy.json':
    npr

  • Start the proxy server with selected configuration 'google.json':
    npr google.json

  • Start the proxy server with multiple configurations 'google.json ms.json':
    npr google.json ms.json

Proxy mode

A configuration proxy.json looks like this:

{
  "microsoft" : {
    "dstPort" : 80,
    "localPort" : 3000,
    "dstAddr" : "www.microsoft.com"
  },
  "google" : {
    "dstPort" : 80,
    "localPort" : 2000,
    "localAddr" : "127.0.0.1",
    "dstAddr" : "www.google.com"
  }
}

means that:
when the clients connect to 127.0.0.1:3000, they connect to www.microsoft.com:80, and when the clients connect to127.0.0.1:2000, they connect to www.google.com:80.

Please note that localAddr is not necessary, when omitted, the server will listen on all network interfaces.

Router mode

Router mode works only with HTTP, not even HTTPS. Proxy mode and router mode can be working together happily. A configuration proxy.json looks like this:

{
  "google_ms" : {
    "localPort" : 4000,
    "routes" : {
      "hostname_a" : {
        "dstAddr" : "www.microsoft.com",
        "dstPort" : 80
      },
      "hostname_b" : {
        "dstAddr" : "www.google.com",
        "dstPort" : 80
      },
      "default" : {
        "dstAddr" : "www.yahoo.com",
        "dstPort" : 80
      }
    }
  }
}

means that:
if multiple host names / domain names are bound to the proxy server, let's say hostname_a and hostname_b. When the clients connect to hostname_a:4000, they connect to www.microsoft.com:80, and when the clients connect to hostname_b:4000, they connect to www.google.com:80. If the clients connect to a host name which is not in the route table, 127.0.0.1:4000 from the proxy server itelf, for example, they connect to the default route www.yahoo.com:80.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值