root@AR:~# npm install -g proxy
/usr/local/bin/proxy -> /usr/local/lib/node_modules/proxy/bin/proxy
proxy@0.2.4 /usr/local/lib/node_modules/proxy
├── basic-auth-parser@0.0.2
├── commander@2.9.0 (graceful-readlink@1.0.1)
└── debug@2.2.0 (ms@0.7.1)
root@AR:~# proxy
HTTP(s) proxy server listening on port 3128
^C
root@AR:~# nohup proxy > /dev/null &
[1] 21563
root@AR:~# nohup: 忽略输入重定向错误到标准输出端
root@AR:~#
root@AR:~# proxy -h
Usage: proxy [options]
Options:
-h, --help output usage information
-V, --version output the version number
-p, --port <n> TCP port number to bind to. Defaults to 3128
-a, --authenticate <command> "authenticate" command to run when "Proxy-Authorization" is given
root@AR:~# nohup proxy -p some_port > /dev/null & (需回车2次)
已测试过,可用作tor的前置代理,从而使得tor browser成功连上tor网络。
--------------------------
proxy
Custom
已测试过,可用作tor的前置代理,从而使得tor browser成功连上tor网络。
--------------------------
proxy
An HTTP proxy written with Node.js (think Squid)
This module provides standard "HTTP proxy" logic. You can script your own server using the
proxy
server API. Be sure to take a look at the "Examples" section below.
There is also a companion
proxy(1)
CLI tool, which spawns an HTTP(s) proxy server with the specified options.
You could think of
proxy(1)
as similar to some of the other popular open source HTTP proxy software:Installation
Install with
npm
:$ npm install proxy
If you would like to have the
proxy(1)
CLI program in your $PATH
, then install "globally":$ npm install -g proxy
Examples
Basic HTTP(s) proxy server
A basic HTTP(s) server with all the default options. All requests are allowed. CONNECT HTTP method works as well.
var http = require('http');
var setup = require('proxy');
var server = setup(http.createServer());
server.listen(3128, function () {
var port = server.address().port;
console.log('HTTP(s) proxy server listening on port %d', port);
});
CLI Tool Examples
The
proxy(1)
CLI tool can be used to spawn HTTP(s) proxy server instances with various options.Port to bind to
Pass the
-p
/--port
option to with a port number to specify a TCP port to bind to. Defaults to 3128 if none is specified.$ proxy --port 8080
Proxy-Authenticate
command
Custom
Pass the
-a
/--authenticate
switch with a command to execute when the client Proxy-Authorization
header is given. This command determines whether or not the request is authorized based on the "exit code" of the command.
The relevant request authentication information is passed in as
PROXY_AUTH_USERNAME
, PROXY_AUTH_PASSWORD
and PROXY_AUTH_SCHEME
environment variables.
For example, to authorize "Basic" authentication with username "foo" and password "bar":
$ proxy --authenticate 'if \
[ "$PROXY_AUTH_USERNAME" = "foo" ] && \
[ "$PROXY_AUTH_PASSWORD" = "bar" ]; \
then exit 0; \
fi; \
exit 1;'