anyproxy/README.md

134 lines
6.4 KiB
Markdown
Raw Normal View History

2014-08-11 16:43:14 +08:00
anyproxy
2014-08-08 17:50:56 +08:00
==========
2014-09-01 17:14:40 +08:00
A fully configurable proxy in NodeJS, which can handle HTTPS requests perfectly.
2014-09-05 14:45:01 +08:00
2014-11-13 10:05:56 +08:00
[wiki - 代理服务器的新轮子](https://github.com/alibaba/anyproxy/wiki/%E4%BB%A3%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E7%9A%84%E6%96%B0%E8%BD%AE%E5%AD%90%EF%BC%9Aanyproxy) 介绍我们为什么要再造一个代理服务器anyproxy与众不同的结构与功能。
2014-09-05 13:53:12 +08:00
2014-09-05 14:02:06 +08:00
![](https://i.alipayobjects.com/i/ecmng/png/201409/3NKRCRk2Uf.png_250x.png)
2014-08-22 16:06:05 +08:00
2014-11-13 10:05:56 +08:00
2014-08-21 17:40:02 +08:00
Feature
------------
* work as http or https proxy
2014-09-03 15:20:57 +08:00
* fully configurable, you can modify a request at any stage by your own javascript code
2014-09-01 17:14:40 +08:00
* when working as https proxy, it can generate and intercept https requests for any domain without complaint by browser (after you trust its root CA)
2014-09-04 11:22:35 +08:00
* a web interface is availabe for you to view request details
2014-09-11 10:22:08 +08:00
* (beta)a web UI interface for you to replace some remote response with local data
2014-11-18 20:02:35 +08:00
* (Chinese in this doc is nothing but translation of some key points. Be relax if you dont understand.)
2014-09-03 16:14:51 +08:00
![screenshot](http://gtms03.alicdn.com/tps/i3/TB1ddyqGXXXXXbXXpXXihxC1pXX-1000-549.jpg_640x640q90.jpg)
2014-09-01 17:14:40 +08:00
2014-11-25 16:43:58 +08:00
Quick Start
2014-08-21 17:40:02 +08:00
--------------
2014-08-13 17:30:16 +08:00
### step 1 - install
2014-09-01 17:23:01 +08:00
* install [NodeJS](http://nodejs.org/)
2014-11-13 10:44:52 +08:00
* ``npm install -g anyproxy`` , may require ``sudo``
* python is optional, it will be OK if you get some error about it during installing.
2014-08-08 17:50:56 +08:00
2014-08-21 17:40:02 +08:00
### step 2 - start server
2014-08-09 11:41:02 +08:00
2014-08-21 17:40:02 +08:00
* start with default settings : ``anyproxy``
* start with a specific port: ``anyproxy --port 8001``
2014-09-04 14:19:55 +08:00
* start with a rule file: ``anyproxy --rule ./rule_sample/rule_allow_CORS.js``
2014-08-13 17:30:16 +08:00
2014-09-03 16:14:51 +08:00
### step 3 - launch web interface
* visit [http://127.0.0.1:8002](http://127.0.0.1:8002) with modern browsers
2014-11-24 16:22:39 +08:00
2014-09-11 11:09:12 +08:00
Rule module
2014-09-01 17:14:40 +08:00
-------------------
2014-11-18 20:02:35 +08:00
* Rule module is the specialty for anyproxy. Unlike other proxy, here you could write your own code to hack requests at any stage, no matter it is about to response or the proxy just gets the request. In this way, it would be much more flexible to meet your own demands.
2014-09-11 11:09:12 +08:00
2014-11-18 20:07:20 +08:00
* It's highly recommended to read this guide before using: [What is rule file and how to write one ?](https://github.com/alibaba/anyproxy/wiki/What-is-rule-file-and-how-to-write-one)
2014-09-11 11:09:12 +08:00
2014-11-24 16:22:39 +08:00
* An entire scheme of rule file could be found at [./rule_sample/rule__blank.js](https://github.com/alibaba/anyproxy/blob/master/rule_sample/rule__blank.js). Besides, there are some samples at [./rule_sample](https://github.com/alibaba/anyproxy/tree/master/rule_sample). That may help you a lot when writing your own rule files.
![](https://t.alipayobjects.com/images/T1v8pbXjJqXXXXXXXX.png)
2014-09-03 15:20:57 +08:00
2014-08-13 17:30:16 +08:00
2014-11-24 16:25:37 +08:00
Https features
2014-08-21 17:40:02 +08:00
----------------
2014-11-18 20:02:35 +08:00
After configuring rootCA, anyproxy could help to decrypt https requests, whose approach is also called Man-In-The-Middle(MITM).
2014-09-22 14:17:18 +08:00
2014-09-01 17:26:24 +08:00
#### step 1 - install openssl
2014-09-07 13:49:39 +08:00
* openssl is availabe here : [http://wiki.openssl.org/index.php/Compilation_and_Installation](http://wiki.openssl.org/index.php/Compilation_and_Installation)
* using ``openssl version -a `` to make sure it is accessible via you command line.
2014-08-21 17:41:54 +08:00
2014-09-01 17:26:24 +08:00
#### step 2 - generate a rootCA and trust it
2014-08-21 17:40:02 +08:00
* you should do this when it is the first time to start anyproxy
2014-09-11 14:55:47 +08:00
* execute ``sudo anyproxy --root`` ,follow the instructions on screen
2014-11-18 20:14:48 +08:00
* [important!]you will see some tip like *rootCA generated at : ~/.anyproxy_certs... . ``cd`` to that directory, add/trust the rootCA.crt file to your system keychain. In OSX, you may do that by open the .crt file directly
2014-09-12 11:00:41 +08:00
* when debug https requests, you have to trust this rootCA on all of your clients.
2014-08-09 11:41:02 +08:00
2014-09-22 14:17:18 +08:00
#### to intercept(decrypt) https requests
* start your anyproxy as normal. When rootCA is generated, it will intercept all the https requests for you automatically.
2014-10-10 10:55:46 +08:00
* if you get a warning like 'unsafe connection', please check if the root CA is correctly trusted .
2014-09-12 11:00:41 +08:00
2014-09-12 14:38:55 +08:00
#### to start an https proxy
2014-08-13 17:30:16 +08:00
* ``anyproxy --type https --host my.domain.com``
* the param ``host`` is required with https proxy and it should be kept exactly what it it when you config your browser. Otherwise, you may get some warning about security.
2014-09-22 14:17:18 +08:00
* using **https proxy** means your request towards proxy will be encrypted. Please notice that this feature has nothing to do with **intercept https requests**.
2014-08-09 11:41:02 +08:00
2014-10-23 11:08:56 +08:00
#### about certs
2014-09-11 10:48:06 +08:00
* root certs and temperary certs are stored at ``path.join(util.getUserHome(),"/.anyproxy_certs/")``
* to get the rootCA.crt file , you may either find it in local dir or download it via anyproxy web interface
2014-09-11 10:48:06 +08:00
* to clear all the temperary certificates ``anyproxy --clear``
2014-11-13 10:44:52 +08:00
* https features may be unstable in windows
2014-08-09 11:41:02 +08:00
2014-09-01 17:14:40 +08:00
Others
2014-08-21 17:40:02 +08:00
-----------------
2014-10-23 11:07:02 +08:00
#### to save request data
2014-10-23 13:39:43 +08:00
* to save request data to local file, use ``` anyproxy --file /path/to/file ```
* anyproxy uses [nedb](https://github.com/louischatriot/nedb) to save request data. Since NeDB's persistence uses an append-only format, you may get some redundant record in local file. For those dupplicated ones with the same id, just use the lastest line of record.
2014-11-18 20:02:35 +08:00
* [TrafficeRecorder](https://github.com/ottomao/TrafficRecorder) is another tool based on anyproxy to help recording all requests. You may have a try.
2014-10-23 11:07:02 +08:00
2014-10-29 16:20:18 +08:00
#### throttling
2014-11-18 20:02:35 +08:00
* for instance, ``` anyproxy --throttle 10 ``` sets the speed limit to 10kb/s (kbyte/sec)
2014-10-29 16:20:18 +08:00
* this is just a rough throttling for downstream, not for network simulation
2014-10-23 11:07:02 +08:00
#### work as a module for nodejs
2014-11-18 20:02:35 +08:00
* use it as a module and develop your own proxy.
2014-08-14 10:59:49 +08:00
```
2014-09-01 17:14:40 +08:00
npm install anyproxy --save
2014-08-14 10:59:49 +08:00
```
```javascript
var proxy = require("anyproxy");
2014-09-04 11:22:35 +08:00
//create cert when you want to use https features
//please manually trust this rootCA when it is the first time you run it
!proxy.isRootCAFileExists() && proxy.generateRootCA();
var options = {
2014-09-18 13:36:27 +08:00
type : "http",
port : 8001,
hostname : "localhost",
rule : require("path/to/my/ruleModule.js"),
2014-10-29 16:20:18 +08:00
dbFile : null, // optional, save request data to a specified file, will use in-memory db if not specified
webPort : 8002, // optional, port for web interface
socketPort : 8003, // optional, internal port for web socket, replace this when it is conflict with your own service
webConfigPort : 8088, // optional, internal port for web config(beta), replace this when it is conflict with your own service
throttle : 10, // optional, speed limit in kb/s
2014-11-04 17:24:34 +08:00
disableWebInterface : false //optional, set it when you don't want to use the web interface
2014-09-04 11:22:35 +08:00
};
new proxy.proxyServer(options);
2014-08-14 10:59:49 +08:00
```
2014-11-17 14:33:08 +08:00
Contact
-----------------
2014-11-18 20:02:35 +08:00
* Please feel free to [raise issue](https://github.com/alibaba/anyproxy/issues), or give us some advice. :)
2014-10-23 11:07:02 +08:00
* anyproxy用户旺旺群1203077233
2014-11-17 14:33:08 +08:00
License
-----------------
* Apache License, Version 2.0