diff --git a/2014-07-13-test/index.html b/2014-07-13-test/index.html new file mode 100644 index 0000000..1f5f3bf --- /dev/null +++ b/2014-07-13-test/index.html @@ -0,0 +1,179 @@ + + + + + test | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+ +

test

+ + +
+
+

Test

+ +
+ +
+
+
+ + +
+ +
+
+
+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/CNAME b/CNAME new file mode 100644 index 0000000..8162ad7 --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +hiproxy.org \ No newline at end of file diff --git a/api/events.html b/api/events.html new file mode 100644 index 0000000..25912b1 --- /dev/null +++ b/api/events.html @@ -0,0 +1,310 @@ + + + + + Events | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Events

+ +
+
+

ProxyServer ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

+ +

+

“start”

Emitted when the hiproxy server(s) start.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| servers | Array | http/https server | +| localIP | String | the local ip address |

+

+

“stop”

Emitted when the hiproxy server(s) stop.

+

Kind: event emitted by ProxyServer

+

“addHostsFile”

Emitted when add hosts file.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| filePath | Array \| String | rewrite file path(s) |

+

+

“addRewriteFile”

Emitted when add rewrite file.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| filePath | Array \| String | rewrite file path(s) |

+

+

“creatPacFile”

Emitter when the pac proxy file is created or updated.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| domains | Object | domain list |

+

+

“httpsRequest”

Emitted each time there is a request to the https server.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request object | +| response | http.ServerResponse | response object |

+

+

“connect”

Emitted each time the server responds to a request with a CONNECT method.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request object | +| socket | net.Socket | socket object | +| head | Buffer | head |

+

+

“setResponse”

Emitted each time the server set response info (eg: headers).

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| response | http.ServerResponse | request object |

+

+

“request”

Emitted each time there is a request.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request object | +| response | http.ServerResponse | response object |

+

+

“getProxyInfo”

Emitted each time the hiproxy server get proxy info for current request.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| proxyInfo | Object | proxy info object |

+

+

“setRequest”

Emitted each time the hiproxy server set request options (eg: headers and host) before request data from remote server

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request | +| proxyOptions | Object | the proxy header options |

+

+

“setResponse”

Emitted each time the server set response info (eg: headers).

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| response | http.ServerResponse | request object |

+

+

“data”

Emitted whenever the response stream received some chunk of data.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| data | Buffer | response data |

+

+

“response”

Emitted when a response is end. This event is emitted only once.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| response | http.ServerResponse | response object |

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/api/index.html b/api/index.html new file mode 100644 index 0000000..2cbafb1 --- /dev/null +++ b/api/index.html @@ -0,0 +1,278 @@ + + + + + Node.js API | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Node.js API

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

+

ProxyServer ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

+ +

new ProxyServer(options)

Hiproxy’s proxy server.

+

| Param | Type | Description | +| — | — | — | +| options | Object | options | +| options.httpPort | Number | The HTTP proxy service port. If 0/null/undefined is passed, an available port number will be automatically assigned. | +| options.httpsPort | Number | HTTPS proxy service port number. If 0 is passed, an available port will be automatically assigned. If pass null or undefined, the HTTPS service will not be started. | +| [options.dir] | String | The hiproxy workspace defaults to the current working directory of the Node.js process(process.cwd()) |

+

+

proxyServer.start([config]) ⇒ Promise

Start proxy server.

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Description | +| — | — | — | +| config | Object | configuration fields |

+

+

proxyServer.stop() ⇒ ProxyServer

Stop proxy server.

+

Kind: instance method of ProxyServer
Access: public

+

proxyServer.restart() ⇒ ProxyServer

Restart proxy server.

+

Kind: instance method of ProxyServer
Access: public

+

proxyServer.addHostsFile(filePath) ⇒ ProxyServer

Add a hosts file.

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Description | +| — | — | — | +| filePath | String \| Array | hosts file path(s) (absolute) |

+

+

proxyServer.addRewriteFile(filePath) ⇒ ProxyServer

Add a rewrite file.

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Description | +| — | — | — | +| filePath | String \| Array | rewrite file path(s) (absolute) |

+

+

proxyServer.openBrowser(browserName, url, [usePacProxy]) ⇒ ProxyServer

Open a browser.

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Default | Description | +| — | — | — | — | +| browserName | String | | browser name | +| url | String | | the URL should be opened | +| [usePacProxy] | Boolean | false | whether use PAC proxy |

+

+

proxyServer.enableConfFile(confFileType, filePath) ⇒ ProxyServer

Enable specified configuration file.

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Default | Description | +| — | — | — | — | +| confFileType | String | | file type (host/rewrite) | +| filePath | String \| Array | | modified file path(s) |

+

+

proxyServer.disableConfFile(confFileType, filePath) ⇒ ProxyServer

Disable specified configuration file.

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Default | Description | +| — | — | — | — | +| confFileType | String | | file type (host/rewrite) | +| filePath | String \| Array | | modified file path(s) |

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/atom.xml b/atom.xml new file mode 100644 index 0000000..0df46bf --- /dev/null +++ b/atom.xml @@ -0,0 +1,41 @@ + + + hiproxy documentation + + A lightweight and powerful proxy tool for front-end developer based on Node.js. + + + + 2018-10-19T09:50:30.295Z + http://hiproxy.org/ + + + hiproxy + + + + Hexo + + + test + + http://hiproxy.org/2014-07-13-test/ + 2018-10-19T09:50:30.295Z + 2018-10-19T09:50:30.295Z + + Test

]]>
+ + + + + + <p>Test</p> + + + + + + +
+ +
diff --git a/browserconfig.xml b/browserconfig.xml new file mode 100644 index 0000000..24a1622 --- /dev/null +++ b/browserconfig.xml @@ -0,0 +1,12 @@ + + + + + + + + + #2f83cd + + + diff --git a/configuration/find_conf.html b/configuration/find_conf.html new file mode 100644 index 0000000..54aa466 --- /dev/null +++ b/configuration/find_conf.html @@ -0,0 +1,234 @@ + + + + + Find Configuration File | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Find Configuration File

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

If you place the configuration file (include the its name) by following hiproxy concept, while hiproxy starts, it can automatically find the file without specifying the configuration file manually.

+

Otherwise, you have to specify the configuration file while hiproxy starts. In the case, you may place the configuration file anywhere, which can be named anything. (Omitted hosts file name is hosts, and rewrite file name is rewrite).

+

Specifiy configuration file

You can use some options to specify the name of configuration file. They are -c, --hosts-file <files> or -r, --rewrite-file <files>.

+

-c, --hosts-file <files> is used to specify the path of hosts file. , can be used to separate more than one files.

+

-r, --rewrite-file <files> is used to specify the path of rewrite file. , can be used to separate more than one files.

+

<files> supports simple wildchar mode to speify more files. For example, --rewrite-file ./*/*.conf.

+
+

Note

+

If you specified a configuration file, hiproxy would look for specified file to instead of looking for omitted hosts ro rewrite. For example: + If `-c .//hosts.confis specified, hiproxy would ignore the file namedhosts. +* If-r ./*/rewrite.confis specified, hiproxy would ignore the file namedrewrite`.

+
+

Wildchars in configuraton files

Suporting wildchars:

+

wildchars | description | example | mached | unmached +———|———-|———|———-|——— + * | Match one or more characters. | ./test-*.js | ./test-hello.js | ./test-.js + ? | Match only one character. | ./test?.js | ./testA.js | ./testAB.js + [abc] | Matches a single character that is contained within the brackets. | ./test[ABC].js | ./testA.js | ./testD.js + [^abc] | Matches a single character that is not contained within the brackets. | ./test[^ABC].js | ./testD.js | ./testA.js + [!abc] | Same as [^abc] | ./test[!ABC].js | ./testD.js | ./testA.js

+
+

Note

+

Do not support use ** to look for files in any hierarchy.

+
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/configuration/hosts.html b/configuration/hosts.html new file mode 100644 index 0000000..a536842 --- /dev/null +++ b/configuration/hosts.html @@ -0,0 +1,221 @@ + + + + + Hosts | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Hosts

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Introduction

Hosts can be thought as enhanced hosts of OS, Its most important feature is port forwarding.

+

Note: hiproxy support both hosts file and rewrite file. hosts is a simple solution so that it supports only forwarding domain & port. If you want custom complex forwarding rules, see rewrite as referrence.

+

Working mechanism

Hiproxy will parse hosts files in the projects’ immediate directories while it starts. The proxy server would forward received requests according to rules in hosts files.

+

Features

    +
  • Port forwarding;
  • +
  • hosts file of project is used to instead of OS one and avoid system cache issue;
  • +
  • You do NOT need to restart hiproxy after modifying hosts file. Hiproxy can restart and refresh hosts rules automatically.
  • +
+

Syntax

The syntax of project hosts is very similar as OS one. Supporting IP+port is the only difference. The syntax is:

+
1
IP[:port] domain1 domain2 domain3 ... domainN
+

For Example

1
2
3
4
# custom hosts with port :)

127.0.0.1:8800 hiproxy.org blog.hiproxy.org
127.0.0.1 hiproxy.org blog.hiproxy.org
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/configuration/index.html b/configuration/index.html new file mode 100644 index 0000000..69835ce --- /dev/null +++ b/configuration/index.html @@ -0,0 +1,232 @@ + + + + + Introduction | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Introduction

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Type of configuration file

Hiproxy can use hosts to make simple request proxy. And rewrite can be used for complex configuration rules which use similar syntax of Nginx.

+

hosts

It has same syntax as hosts of OS. As additinal, it supports configurating port number. You can only configure host with corresponding IP and port in hosts. It does not support detailed routing and modification to request/response. Read hosts for more.

+

Example for hosts

1
2
3
4
5
# comment
127.0.0.1 example.com

# ip + port
127.0.0.1:8800 blog.example.com life.example.com
+

rewrite

You can make complex configuration in rewrite in some complex situation. That includes detailed routing, and modification to request/response. The syntax of rewirte configuration is very similar to that of Nginx. Read rewrite for more.

+

Example for rewrite

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# global variables
set $port 8899;
set $ip 127.0.0.1;
set $online 210.0.0.0;

# domain name configuration
domain example.com {
location / {
proxy_pass http://$online/;
}

location /blog/ {
proxy_pass http://$ip:$port/blog/;
proxy_set_header from 'hiproxy';
set_header proxy 'hiproxy';
}
}
+

Configuration file location

hiproxy recommends you place configuration files in the particular project root directory (hosts file named hosts and rewrite file named rewrite). Projects are placed in workspace so that the hierarchy structure is line below:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
workspace
├── app-1 # Project1
│   ├── hosts # hosts file
│   ├── rewrite # rewrite file
│   └── src # codes
│   └── ... # other files

├── app-2 # Project2
│   ├── hosts # hosts file
│   ├── rewrite # rewrite file
│   └── src # codes
│   └── ... # other files

└── app-3 # Project3
├── hosts # hosts file
├── rewrite # rewrite file
└── src # codes
   └── ... # other files
+

The benifit is that these configuration files can be commit to code repository for sharing with team members, and cost saving. Furthermore, hiproxy can find the files by itself.

+

Finding configuration files

If you follow the rules above to place the files (with their special names), and hiproxy use workspace directory as workspace, it can find the configuration files of the three projects without spcifying by manual.

+

If you do NOT follow the rules, place the files to different directory or not use default names (hosts for hosts file and rewrite for rewrite file), you have to specify the files while hiproxy starts.

+

Read Find Configuration File for more.

+

Update configuration files

Hiproxy support two proxy methods: PAC(Proxy-Auto-Config) and general proxy.

+

General proxy method is default one. You can use --pac-proxy for swithing to PAC while starting.

+

The Deifferent proxy methods deal updating configuration file in different way.

+

If it’s running in general proxy mode and the configuration file was updated. You can just refresh the browsing page to make it valid.

+

But if it’s running in PAC proxy mode, and one or more new domain ware added. You should refresh the browser’s proxy file by manual since the .pac file is not updated immediately. If you want detail, you can visit chrome://net-internals/#proxy then click Re-apply settings.

+

Merge proxy rules

The rules in all configuration files should be merged into a bit rules tree. That is, after configuring the proxy, all the rules in the configuration files are equal at the time the request is processing. The rules in different domain would not affect each other. The rules in the same domain should be merged and later rule should overwrite previous one if they are same route.

+

For example, there are two configuration files, workspace/blog/rewrite and workspace/docs/rewrite. Their content are below:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
# workspace/blog/rewrite

domain hiproxy.org {
location /blog/ {
proxy_pass http://127.0.0.1:8000/;
}
}

domain blog.hiproxy.org {
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
+
1
2
3
4
5
6
7
# workspace/docs/rewrite

domain hiproxy.org {
location /docs/ {
proxy_pass http://127.0.0.1:9000/;
}
}
+

After merging:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# merged rules

domain hiproxy.org {
location /blog/ {
proxy_pass http://127.0.0.1:8000/;
}
}

domain hiproxy.org {
location /docs/ {
proxy_pass http://127.0.0.1:9000/;
}
}

domain blog.hiproxy.org {
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/configuration/rewrite.html b/configuration/rewrite.html new file mode 100644 index 0000000..782569a --- /dev/null +++ b/configuration/rewrite.html @@ -0,0 +1,210 @@ + + + + + Rewrite | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/configuration/ssl_certificate.html b/configuration/ssl_certificate.html new file mode 100644 index 0000000..6c92fd4 --- /dev/null +++ b/configuration/ssl_certificate.html @@ -0,0 +1,290 @@ + + + + + Get And Install SSL Certificate | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Get And Install SSL Certificate

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Hiproxy can generate its own root certificate. You can think it as a CA (Hiproxy Custom CA). If a https request need hiproxy to forward, hiproxy would use its own root certificate to generate automatically a secure certification of that https request.

+

Hiproxy own root certificate is not trusted by OS, therefore, you have to install the root certificate by manual to let OS know it as trusted one.

+

Download The Certificate

As soon as hiproxy is started (suppose the port number is 5525), you can go http://127.0.0.1:5525/ssl-certificate to get the root certificate of Hiproxy Custom CA.

+

You can get the URL from http://127.0.0.1:5525/ by following below image:

+

+

Install Certificate

The following describes how the root certificate is installed in OSX, iOS, Windows and Android.

+

Mac OSX

    +
  1. Double click downloaded Hiproxy_Custom_CA_Certificate.pem to import the certificate to keychain.

    +
  2. +
  3. Input your username and password in popuped dialog.

    +
  4. +
  5. Now the certificate is not trusted. You should double click the certificate which is imported in previous step.

    +
  6. +
+

+
    +
  1. Choose Always trust by following Trust > While using this certificate.
  2. +
+

+
    +
  1. Close the dialog. Now the certificate is in trusted state.
  2. +
+

+

iOS

    +
  1. Send the downloaded certificate to iPhone then open it in iOS.

    +
  2. +
  3. Click Install on the top right of the view.

    +
  4. +
+

+
    +
  1. Click Install to confirm.
  2. +
+

+
    +
  1. After complate installing, click Complete to finish and exit installing.
  2. +
+

+
    +
  1. If the iOS version >= 10.3, you have to click Certificate trust settings by following Settings > General > About this iPhone.
  2. +
+

+
    +
  1. Open the switcher on Hiproxy Custom CA.
  2. +
+

+

Windows

    +
  1. Double click downloaded Hiproxy_Custom_CA_Certificate.crt to install the certificate.

    +
  2. +
  3. Click Install certificate on the popuped dialog.

    +
  4. +
+

+
    +
  1. Click Next.
  2. +
+

+
    +
  1. Choose Persist all certificates in below storage(P) then click Browse(R) and select Trusted CA, click OK
  2. +
+

+
    +
  1. Click Next, then Finish. Complete the certificate installing by following wizard.
  2. +
+

+

Android

    +
  1. Download the certificate and send it to mobile.

    +
  2. +
  3. Click Install from SD card by following Settings > Security.

    +
  4. +
+

+
    +
  1. Input the unlock password then certificate name, for example HiproxyCustomCA, then click OK.
  2. +
+

+
    +
  1. Follow Settings > Security > Trusted certificate > Users. If you can find hiproxy root certificate, it succeeds.
  2. +
+

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/css/navy.css b/css/navy.css new file mode 100644 index 0000000..eff5f01 --- /dev/null +++ b/css/navy.css @@ -0,0 +1,1581 @@ +html, +body, +div, +span, +applet, +object, +iframe, +h1, +h2, +h3, +h4, +h5, +h6, +p, +blockquote, +pre, +a, +abbr, +acronym, +address, +big, +cite, +code, +del, +dfn, +em, +img, +ins, +kbd, +q, +s, +samp, +small, +strike, +strong, +sub, +sup, +tt, +var, +dl, +dt, +dd, +ol, +ul, +li, +fieldset, +form, +label, +legend, +table, +caption, +tbody, +tfoot, +thead, +tr, +th, +td { + margin: 0; + padding: 0; + border: 0; + outline: 0; + font-weight: inherit; + font-style: inherit; + font-family: inherit; + font-size: 100%; + vertical-align: baseline; +} +body { + line-height: 1; + color: #000; + background: #fff; +} +ol, +ul { + list-style: none; +} +table { + border-collapse: separate; + border-spacing: 0; + vertical-align: middle; +} +caption, +th, +td { + text-align: left; + font-weight: normal; + vertical-align: middle; +} +a img { + border: none; +} +html { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +*, +*:before, +*:after { + -webkit-box-sizing: inherit; + -moz-box-sizing: inherit; + box-sizing: inherit; +} +button::-moz-focus-inner, +input[type="reset"]::-moz-focus-inner, +input[type="button"]::-moz-focus-inner, +input[type="submit"]::-moz-focus-inner { + padding: 0; + margin: 0; + border: 0; +} +input, +button, +select { + margin: 0; + padding: 0; + border: 0; +} +@media screen { + html, + body { + height: 100%; + } +} +body { + background: #171f26; + font-size: 15px; + font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; + color: #444; + text-rendering: optimizeLegibility; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; + overflow-x: hidden; +} +.wrapper:before, +.wrapper:after { + content: ""; + display: table; +} +.wrapper:after { + clear: both; +} +@media screen { + .wrapper { + max-width: 1200px; + margin: 0 auto; + } +} +.inner:before, +#article-toc-inner:before, +.inner:after, +#article-toc-inner:after { + content: ""; + display: table; +} +.inner:after, +#article-toc-inner:after { + clear: both; +} +@media screen { + .inner, + #article-toc-inner { + padding: 0 20px; + } +} +#content-wrap { + background: #fff; + border-top: 1px solid #161d24; + border-bottom: 1px solid #161d24; + margin: -1px 0; +} +#header { + position: relative; + padding: 10px 0; +} +@media print { + #header { + display: none; + } +} +#header-inner { + display: -webkit-box; + display: -moz-box; + display: -webkit-flex; + display: -ms-flexbox; + display: box; + display: flex; + -webkit-box-orient: horizontal; + -moz-box-orient: horizontal; + -webkit-box-lines: single; + -moz-box-lines: single; + -webkit-flex-flow: row nowrap; + -ms-flex-flow: row nowrap; + flex-flow: row nowrap; + -webkit-box-align: center; + -moz-box-align: center; + -ms-flex-align: center; + -webkit-align-items: center; + align-items: center; +} +@media screen and (max-width: 768px) { + #header-inner { + -webkit-box-pack: center; + -moz-box-pack: center; + -ms-flex-pack: center; + -webkit-justify-content: center; + justify-content: center; + } +} +#logo-wrap { + -webkit-box-flex: 1; + -moz-box-flex: 1; + box-flex: 1; + -webkit-flex: 0 50px; + -ms-flex: 0 50px; + flex: 0 50px; +} +#logo { + text-indent: 101%; + white-space: nowrap; + overflow: hidden; + background: url("/logo-light.svg"); + width: 50px; + height: 50px; + -webkit-background-size: 50px 50px; + -moz-background-size: 50px 50px; + background-size: 50px 50px; + display: block; +} +#main-nav { + display: none; + -webkit-box-flex: 1; + -moz-box-flex: 1; + box-flex: 1; + -webkit-flex: 1 auto; + -ms-flex: 1 auto; + flex: 1 auto; + padding-left: 20px; +} +@media screen and (min-width: 769px) { + #main-nav { + display: block; + } +} +.main-nav-link { + color: #fff; + text-decoration: none; + line-height: 50px; + opacity: 0.7; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + display: inline-block; + padding: 0 15px; +} +.main-nav-link:hover { + opacity: 1; + color: #1094e8; +} +#lang-select-wrap { + display: none; + position: relative; +} +@media screen and (min-width: 769px) { + #lang-select-wrap { + display: block; + } +} +#lang-select-label { + color: #fff; + opacity: 0.7; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + line-height: 50px; +} +#lang-select-label span { + padding-left: 8px; +} +#lang-select-label i { + opacity: 0.7; +} +#lang-select { + opacity: 0; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + -webkit-appearance: menulist-button; + font-size: inherit; +} +#banner { + color: rgba(255,255,255,0.8); + text-align: center; +} +#banner-title { + padding-top: 20px; + font-size: 40px; + line-height: 1.15; + font-weight: 300; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; +} +@media screen and (min-width: 769px) { + #banner-title { + padding-top: 100px; + font-size: 50px; + } +} +#banner-start { + text-align: center; + padding: 40px 0; +} +@media screen and (min-width: 769px) { + #banner-start { + padding: 60px 0; + font-size: 18px; + } +} +#banner-start-command { + background: #283542; + font-family: "Source Code Pro", Monaco, Menlo, Consolas, monospace; + display: inline-block; + padding: 15px 20px; + border-bottom-left-radius: 2px; + border-top-left-radius: 2px; +} +#banner-start-command:before { + content: "$"; + opacity: 0.5; + padding-right: 10px; +} +#banner-start-link { + color: #fff; + background: #0e83cd; + display: inline-block; + padding: 15px; + text-decoration: none; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; + border-top-right-radius: 2px; + border-bottom-right-radius: 2px; +} +#banner-start-link:hover { + background: #1094e8; +} +#banner-share { + display: none; + padding-bottom: 60px; +} +@media screen and (min-width: 769px) { + #banner-share { + display: block; + } +} +#intro-feature-list { + padding-top: 20px; + display: -webkit-box; + display: -moz-box; + display: -webkit-flex; + display: -ms-flexbox; + display: box; + display: flex; + -webkit-box-orient: vertical; + -moz-box-orient: vertical; + -webkit-flex-flow: column; + -ms-flex-flow: column; + flex-flow: column; +} +@media screen and (min-width: 769px) { + #intro-feature-list { + -webkit-box-orient: horizontal; + -moz-box-orient: horizontal; + -webkit-box-lines: multiple; + -moz-box-lines: multiple; + -webkit-flex-flow: row wrap; + -ms-flex-flow: row wrap; + flex-flow: row wrap; + } +} +.intro-feature-wrap { + padding-top: 20px; +} +@media screen and (min-width: 769px) { + .intro-feature-wrap { + -webkit-box-flex: 1; + -moz-box-flex: 1; + box-flex: 1; + -webkit-flex: 0 0 50%; + -ms-flex: 0 0 50%; + flex: 0 0 50%; + padding-top: 50px; + } +} +.intro-feature { + position: relative; + text-align: center; +} +@media screen and (min-width: 769px) { + .intro-feature { + text-align: left; + padding-left: 70px; + } +} +.intro-feature-icon { + color: #0e83cd; + font-size: 36px; + padding-bottom: 26px; + text-align: center; +} +@media screen and (min-width: 769px) { + .intro-feature-icon { + position: absolute; + top: 0; + left: 20px; + font-size: 24px; + width: 24px; + } +} +.intro-feature-title { + color: #0e83cd; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 24px; +} +.intro-feature-desc { + margin: 1.6em 0; + line-height: 1.6em; +} +#intro-cmd-wrap { + max-width: 700px; + background: #eee; + padding: 15px 0; + margin: 25px -20px 0; +} +@media screen and (min-width: 769px) { + #intro-cmd-wrap { + margin: 50px auto 0; + } +} +.intro-cmd-item { + font-size: 16px; + font-family: "Source Code Pro", Monaco, Menlo, Consolas, monospace; + line-height: 2; + padding: 0 30px; +} +.intro-cmd-item:before { + content: "$"; + color: #0e83cd; + padding-right: 15px; +} +#intro-get-started-wrap { + text-align: center; +} +#intro-get-started-link { + font-size: 18px; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + display: inline-block; + color: #fff; + text-decoration: none; + margin: 40px 0; + background-color: #25a1f0; + padding: 10px 24px; + position: relative; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; + border-radius: 2px; + -webkit-box-shadow: 0 2px 5px 0 rgba(0,0,0,0.26); + box-shadow: 0 2px 5px 0 rgba(0,0,0,0.26); +} +#intro-get-started-link:hover { + background: #4285f4; + color: #fff; +} +#sidebar { + width: 220px; + float: left; + padding-bottom: 40px; + opacity: 0.8; + margin-left: -220px; + display: none; +} +@media screen and (min-width: 769px) { + #sidebar { + display: block; + } +} +.sidebar-title { + width: 100%; + margin-top: 40px; + padding: 10px 0; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: bold; + color: #0e83cd; + display: inline-block; + border-top: 1px solid #e3e3e3; + line-height: 1; +} +.sidebar-link, +.toc-link { + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + display: block; + color: #444; + text-decoration: none; + padding: 7px 0; + line-height: 1; + position: relative; + width: 100%; + text-overflow: ellipsis; + overflow: hidden; + white-space: nowrap; +} +.sidebar-link.current, +.toc-link.current { + color: #0e83cd; +} +.sidebar-link:hover, +.toc-link:hover { + color: #1094e8; +} +#content { + position: relative; +} +#content:before, +#content:after { + content: ""; + display: table; +} +#content:after { + clear: both; +} +#content-inner:before, +#content-inner:after { + content: ""; + display: table; +} +#content-inner:after { + clear: both; +} +@media screen and (min-width: 769px) { + #content-inner { + margin-left: 220px; + } +} +@media screen and (min-width: 769px) { + .article-container { + float: right; + width: 100%; + } +} +.article-inner:before, +.article-inner:after { + content: ""; + display: table; +} +.article-inner:after { + clear: both; +} +@media screen and (min-width: 769px) { + .article-inner { + margin-right: 220px; + } +} +.article { + float: left; + width: 100%; + padding: 40px 0; +} +@media print { + .article { + padding: 0; + } +} +#article-toc { + display: none; + float: right; + width: 220px; + margin-right: -220px; + opacity: 0.8; +} +@media screen and (min-width: 769px) { + #article-toc { + display: block; + } +} +#article-toc.fixed { + position: absolute; + top: 0; + bottom: 0; + right: 220px; +} +#article-toc-inner { + overflow-x: hidden; + overflow-y: auto; + width: 220px; +} +.fixed #article-toc-inner { + position: fixed; + top: 0; + bottom: 0; +} +.toc-child { + padding-left: 1em; + font-size: 0.9em; +} +#article-toc-top { + margin-top: 2em; + font-size: 0.9em; + text-decoration: none; + color: #444; + display: block; + margin-bottom: 40px; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; +} +#article-toc-top:hover { + color: #1094e8; +} +.article-header { + padding-bottom: 20px; +} +.article-header:before, +.article-header:after { + content: ""; + display: table; +} +.article-header:after { + clear: both; +} +.article-title { + float: left; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 36px; + font-weight: 300; + text-decoration: none; + color: #444; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; +} +a.article-title:hover { + color: #1094e8; +} +.post .article-title { + float: none; +} +.article-date { + color: #999; + text-decoration: none; + display: inline-block; + margin-top: 1em; +} +.article-date:hover { + color: #1094e8; +} +.article-edit-link { + float: right; + color: #bbb; + font-size: 24px; + line-height: 36px; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; + display: none; +} +.article-edit-link:hover { + color: #1094e8; +} +@media screen and (min-width: 769px) { + .article-edit-link { + display: block; + } +} +.article-anchor { + margin-left: 10px; + display: none; +} +.article-anchor:before { + content: "#"; +} +@media print { + .article-anchor { + display: none !important; + } +} +.article-heading:hover .article-anchor { + display: inline-block; +} +.article-content { + line-height: 1.6em; + color: #444; +} +@media print { + .article-content { + font-size: 12pt; + } +} +.article-content p, +.article-content ol, +.article-content ul, +.article-content dl, +.article-content table, +.article-content blockquote, +.article-content iframe, +.article-content .highlight { + margin: 1em 0; +} +.article-content h1 { + font-size: 2em; +} +.article-content h2 { + font-size: 1.5em; +} +.article-content h3 { + font-size: 1.3em; +} +.article-content h1, +.article-content h2, +.article-content h3, +.article-content h4, +.article-content h5, +.article-content h6 { + line-height: 1em; + font-weight: bold; + margin: 1em 0; +} +.article-content a { + color: #0e83cd; + text-decoration: none; +} +.article-content a:hover { + color: #1094e8; + text-decoration: underline; +} +@media print { + .article-content a { + color: #444; + text-decoration: underline; + } + .article-content a:after { + content: " (" attr(href) ")"; + font-size: 80%; + } +} +.article-content strong { + font-weight: bold; +} +.article-content em { + font-style: italic; +} +.article-content ul, +.article-content ol, +.article-content dl { + margin-left: 20px; +} +.article-content ul ul, +.article-content ol ul, +.article-content dl ul, +.article-content ul ol, +.article-content ol ol, +.article-content dl ol, +.article-content ul dl, +.article-content ol dl, +.article-content dl dl { + margin-top: 0; + margin-bottom: 0; +} +.article-content ul { + list-style: disc; +} +.article-content ol { + list-style: decimal; +} +.article-content dl { + list-style: square; +} +.article-content li p { + margin: 0; +} +.article-content li table, +.article-content li blockquote, +.article-content li iframe, +.article-content li .highlight { + margin: 1em 0; +} +.article-content img, +.article-content video { + max-width: 100%; +} +.article-content blockquote { + padding: 0 20px; + position: relative; + border: 1px solid #e3e3e3; + border-left: 5px solid #ddd; +} +.article-content blockquote footer { + margin: 1em 0; + font-style: italic; +} +.article-content blockquote footer cite:before { + content: "—"; + padding: 0 0.3em; +} +.article-content blockquote footer cite a { + color: color-grey; +} +.article-content .note.tip { + border-left-color: #fa0; +} +.article-content .note.info { + border-left-color: #0af; +} +.article-content .note.warn { + border-left-color: #f00; +} +.article-content .note-title { + margin: 1em 0; + display: block; + font-size: 1.3em; + font-weight: bold; +} +.article-content table { + max-width: 100%; + border: 1px solid #e3e3e3; +} +.article-content table th { + font-weight: bold; +} +.article-content table th, +.article-content table td { + padding: 5px 15px; +} +.article-content table tr:nth-child(2n) { + background: #eee; +} +.article-footer { + margin: 1em 0; + border-top: 1px solid #e3e3e3; + text-align: center; + color: #999; + line-height: 1em; + padding-top: 1em; + position: relative; +} +.article-footer:before, +.article-footer:after { + content: ""; + display: table; +} +.article-footer:after { + clear: both; +} +@media print { + .article-footer { + display: none; + } +} +.article-footer-prev, +.article-footer-next { + color: #0e83cd; + text-decoration: none; + font-weight: bold; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + text-transform: uppercase; + position: absolute; +} +.article-footer-prev:hover, +.article-footer-next:hover { + color: #1094e8; +} +@media print { + .article-footer-prev, + .article-footer-next { + display: none; + } +} +.article-footer-prev span, +.article-footer-next span { + padding: 0 6px; +} +.article-footer-prev { + left: 0; +} +.article-footer-next { + right: 0; +} +.article-footer-updated { + font-size: 0.9em; +} +@media print { + #comments { + display: none; + } +} +.post { + margin: 0 auto; + float: none; +} +@media screen { + .post { + max-width: 800px; + } +} +#plugin-list-header { + margin: 40px 0; +} +#plugin-list-header:before, +#plugin-list-header:after { + content: ""; + display: table; +} +#plugin-list-header:after { + clear: both; +} +#plugin-list-title { + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + font-size: 36px; + font-weight: 300; + line-height: 1; + float: left; +} +#plugin-list-count { + color: #999; + padding-top: 1em; + text-align: right; +} +@media screen and (min-width: 769px) { + #plugin-list-count { + float: right; + line-height: 40px; + padding-top: 0; + padding-right: 15px; + } +} +#plugin-search-input { + font-size: 16px; + font-family: inherit; + -webkit-appearance: none; + border: 1px solid #e3e3e3; + padding: 10px 10px; + width: 100%; + margin-top: 25px; +} +@media screen and (min-width: 769px) { + #plugin-search-input { + float: right; + width: 50%; + margin-top: 0; + } +} +#plugin-list { + margin: 40px -20px; + display: -webkit-box; + display: -moz-box; + display: -webkit-flex; + display: -ms-flexbox; + display: box; + display: flex; + -webkit-box-orient: vertical; + -moz-box-orient: vertical; + -webkit-flex-flow: column; + -ms-flex-flow: column; + flex-flow: column; +} +@media screen and (min-width: 480px) { + #plugin-list { + -webkit-box-orient: horizontal; + -moz-box-orient: horizontal; + -webkit-box-lines: multiple; + -moz-box-lines: multiple; + -webkit-flex-flow: row wrap; + -ms-flex-flow: row wrap; + flex-flow: row wrap; + } +} +.plugin { + display: none; + padding: 20px; +} +@media screen and (min-width: 480px) { + .plugin { + -webkit-box-flex: 1; + -moz-box-flex: 1; + box-flex: 1; + -webkit-flex: 0 0 50%; + -ms-flex: 0 0 50%; + flex: 0 0 50%; + } +} +@media screen and (min-width: 769px) { + .plugin { + -webkit-box-flex: 1; + -moz-box-flex: 1; + box-flex: 1; + -webkit-flex: 0 0 33.333333333333336%; + -ms-flex: 0 0 33.333333333333336%; + flex: 0 0 33.333333333333336%; + } +} +.plugin.on { + display: block; +} +.plugin-name { + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + font-weight: bold; + color: #0e83cd; + font-size: 20px; + text-decoration: none; + line-height: 1; +} +.plugin-name:hover { + color: #1094e8; +} +.plugin-desc { + line-height: 1.6em; + margin: 1em 0; +} +.plugin-tag-list { + line-height: 1.3; +} +.plugin-tag-list:before, +.plugin-tag-list:after { + content: ""; + display: table; +} +.plugin-tag-list:after { + clear: both; +} +.plugin-tag { + color: #999; + font-size: 0.9em; + text-decoration: none; + float: left; + margin-right: 10px; +} +.plugin-tag:hover { + color: #1094e8; +} +.plugin-tag:before { + content: "#"; +} +.plugin-screenshot { + margin-bottom: 15px; + position: relative; + padding-top: 62.5%; + height: 0; + overflow: hidden; +} +.plugin-screenshot-img { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + -webkit-transition: opacity 0.3s; + -moz-transition: opacity 0.3s; + -ms-transition: opacity 0.3s; + transition: opacity 0.3s; +} +.plugin-screenshot-img.lazyload, +.plugin-screenshot-img.lazyloading { + opacity: 0; +} +.plugin-screenshot-img.lazyloaded { + opacity: 1; +} +.plugin-preview-link { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0,0,0,0.7); + color: #fff; + text-align: center; + opacity: 0; + -webkit-transition: 0.15s; + -moz-transition: 0.15s; + -ms-transition: 0.15s; + transition: 0.15s; +} +.plugin-preview-link:hover { + opacity: 1; +} +.plugin-preview-link:hover .fa { + opacity: 1; + -webkit-transform: scale(1); + -moz-transform: scale(1); + -ms-transform: scale(1); + transform: scale(1); +} +.plugin-preview-link .fa { + position: absolute; + top: 0; + left: 0; + bottom: 0; + right: 0; + margin: auto; + font-size: 50px; + width: 50px; + height: 50px; + opacity: 0; + -webkit-transform: scale(6); + -moz-transform: scale(6); + -ms-transform: scale(6); + transform: scale(6); + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; + -webkit-transition-delay: 0.15s; + -moz-transition-delay: 0.15s; + -ms-transition-delay: 0.15s; + transition-delay: 0.15s; +} +.archive-post { + padding: 1em 0; + border-top: 1px solid #e3e3e3; +} +.archive-post:last-child { + padding-bottom: 40px; +} +.archive-post-link { + display: block; + color: #444; + text-decoration: none; + line-height: 1.6em; +} +.archive-post-link:before, +.archive-post-link:after { + content: ""; + display: table; +} +.archive-post-link:after { + clear: both; +} +.archive-post-link:hover { + color: #1094e8; +} +.archive-post-title { + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + float: left; + font-weight: bold; +} +.archive-post-date { + color: #999; + float: right; + font-size: 0.9em; +} +#mobile-nav { + position: fixed; + top: 0; + width: 260px; + left: -260px; + height: 100%; + background: #171f26; + -webkit-transition: 0.4s; + -moz-transition: 0.4s; + -ms-transition: 0.4s; + transition: 0.4s; + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; +} +.mobile-nav-on #mobile-nav { + -webkit-transform: translateX(100%); + -moz-transform: translateX(100%); + -ms-transform: translateX(100%); + transform: translateX(100%); +} +#mobile-nav-inner { + overflow-y: auto; + padding: 10px 0; + position: absolute; + top: 0; + bottom: 40px; + left: 0; + right: 0; + -webkit-overflow-scrolling: touch; +} +#mobile-nav-toggle { + position: absolute; + top: 0; + bottom: 0; + left: 20px; + width: 25px; + height: 20px; + margin: auto; + opacity: 0.5; + cursor: pointer; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; +} +#mobile-nav-toggle:active, +.mobile-nav-on #mobile-nav-toggle { + opacity: 1; +} +@media screen and (min-width: 769px) { + #mobile-nav-toggle { + display: none; + } +} +.mobile-nav-toggle-bar { + background: #fff; + position: absolute; + left: 0; + width: 100%; + height: 2px; + -webkit-transition: 0.4s; + -moz-transition: 0.4s; + -ms-transition: 0.4s; + transition: 0.4s; + -webkit-transform-origin: 0; + -moz-transform-origin: 0; + -ms-transform-origin: 0; + transform-origin: 0; + border-radius: 2px; +} +.mobile-nav-toggle-bar:first-child { + top: 0; +} +.mobile-nav-on .mobile-nav-toggle-bar:first-child { + -webkit-transform: rotate(45deg); + -moz-transform: rotate(45deg); + -ms-transform: rotate(45deg); + transform: rotate(45deg); +} +.mobile-nav-toggle-bar:nth-child(2) { + top: 9px; +} +.mobile-nav-on .mobile-nav-toggle-bar:nth-child(2) { + opacity: 0; +} +.mobile-nav-toggle-bar:last-child { + top: 18px; +} +.mobile-nav-on .mobile-nav-toggle-bar:last-child { + -webkit-transform: rotate(-45deg); + -moz-transform: rotate(-45deg); + -ms-transform: rotate(-45deg); + transform: rotate(-45deg); +} +.mobile-nav-link { + color: #fff; + text-decoration: none; + display: block; + padding: 10px 15px; + line-height: 1; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +.mobile-nav-title { + color: #0e83cd; + font-weight: bold; + padding: 10px 15px; + line-height: 1; + display: block; + border-top: 1px solid #444; + margin-top: 10px; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} +#mobile-lang-select-wrap { + position: absolute; + bottom: 0; + left: 0; + width: 100%; + background: #171f26; + border-top: 1px solid #444; +} +#mobile-lang-select-label { + line-height: 40px; + color: #fff; + padding: 10px 15px; +} +#mobile-lang-select-label i { + opacity: 0.7; +} +#mobile-lang-select-label span { + padding-left: 8px; +} +#mobile-lang-select { + -webkit-appearance: menulist-button; + opacity: 0; + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; +} +#container { + -webkit-transition: 0.4s; + -moz-transition: 0.4s; + -ms-transition: 0.4s; + transition: 0.4s; + height: 100%; + -webkit-overflow-scrolling: touch; +} +.mobile-nav-on #container { + -webkit-transform: translateX(260px); + -moz-transform: translateX(260px); + -ms-transform: translateX(260px); + transform: translateX(260px); + overflow: hidden; +} +#mobile-nav-dimmer { + position: absolute; + top: 0; + left: 100%; + height: 100%; + background: #000; + opacity: 0; + -webkit-transition: opacity 0.4s, -webkit-transform 0s 0.4s; + -moz-transition: opacity 0.4s, -moz-transform 0s 0.4s; + -ms-transition: opacity 0.4s, -ms-transform 0s 0.4s; + transition: opacity 0.4s, transform 0s 0.4s; +} +.mobile-nav-on #mobile-nav-dimmer { + width: 100%; + opacity: 0.7; + -webkit-transform: translateX(-100%); + -moz-transform: translateX(-100%); + -ms-transform: translateX(-100%); + transform: translateX(-100%); + -webkit-transition: opacity 0.4s; + -moz-transition: opacity 0.4s; + -ms-transition: opacity 0.4s; + transition: opacity 0.4s; +} +#footer { + padding: 40px 0; + color: rgba(255,255,255,0.6); + font-family: Lato, "Helvetica Neue", Helvetica, Arial, sans-serif; + position: relative; + background: #171f26; + text-align: center; +} +#footer:before, +#footer:after { + content: ""; + display: table; +} +#footer:after { + clear: both; +} +@media screen and (min-width: 769px) { + #footer { + text-align: left; + } +} +@media print { + #footer { + display: none; + } +} +#footer a { + color: inherit; + text-decoration: none; + -webkit-transition: 0.2s; + -moz-transition: 0.2s; + -ms-transition: 0.2s; + transition: 0.2s; +} +#footer a:hover { + color: #fff; +} +#footer .column { + width: 100%; + margin-top: 3em; +} +@media screen and (min-width: 769px) { + #footer .column { + margin-top: 0; + width: 25%; + float: left; + } +} +#footer .column:first-child { + margin-top: 0; +} +#footer .column-title { + margin-bottom: 1em; + font-weight: bold; +} +#footer .column-title i { + margin-right: 0.5em; +} +#footer .links .link-item { + padding-left: 0; + list-style: none; + margin-top: 10px; +} +#footer .links .link-item:first-child { + margin-top: 0; +} +#footer-copyright { + line-height: 1.4; +} +@media screen and (min-width: 769px) { + #footer-copyright { + float: left; + } +} +#footer-copyright a { + font-weight: bold; +} +#footer-links { + margin-top: 1em; +} +@media screen and (min-width: 769px) { + #footer-links { + float: right; + margin-top: 0; + } +} +.footer-link { + font-size: 30px; + margin-left: 20px; +} +.footer-link:first-child { + margin-left: 0; +} +pre, +code { + font-family: "Source Code Pro", Monaco, Menlo, Consolas, monospace; + color: #4d4d4c; + background: #eee; + font-size: 0.95em; +} +code { + padding: 0 5px; +} +pre { + padding: 10px 15px; + line-height: 22px; +} +pre code { + border: none; + display: block; + padding: 0; +} +.highlight { + background: #eee; + padding: 10px 15px; + color: #4d4d4c; + overflow: auto; + margin: 0; +} +.highlight table { + margin: 0 !important; + border: 0; +} +.highlight table th, +.highlight table td { + padding: 0; +} +.highlight figcaption { + margin: -5px 0 5px; + font-size: 0.9em; + color: #999; +} +.highlight figcaption:before, +.highlight figcaption:after { + content: ""; + display: table; +} +.highlight figcaption:after { + clear: both; +} +.highlight figcaption a { + float: right; +} +.highlight pre { + padding: 0; + border: none; + background: none; +} +.highlight .line { + height: 22px; +} +.highlight .gutter { + padding-right: 10px; +} +pre .comment, +pre .title { + color: #8e908c; +} +pre .variable, +pre .attribute, +pre .tag, +pre .regexp, +pre .ruby .constant, +pre .xml .tag .title, +pre .xml .pi, +pre .xml .doctype, +pre .html .doctype, +pre .css .id, +pre .css .class, +pre .css .pseudo { + color: #c82829; +} +pre .number, +pre .preprocessor, +pre .built_in, +pre .literal, +pre .params, +pre .constant { + color: #f5871f; +} +pre .class, +pre .ruby .class .title, +pre .css .rules .attribute { + color: #718c00; +} +pre .string, +pre .value, +pre .inheritance, +pre .header, +pre .ruby .symbol, +pre .xml .cdata { + color: #718c00; +} +pre .css .hexcolor { + color: #3e999f; +} +pre .function, +pre .python .decorator, +pre .python .title, +pre .ruby .function .title, +pre .ruby .title .keyword, +pre .perl .sub, +pre .javascript .title, +pre .coffeescript .title { + color: #4271ae; +} +pre .keyword, +pre .javascript .function { + color: #8959a8; +} +#carbonads { + display: block; + overflow: hidden; + margin-top: 40px; + max-width: 130px; + text-align: left; + font-size: 13px; + line-height: 1.5; +} +#carbonads a { + color: inherit; + text-decoration: none; +} +#carbonads:hover { + color: inherit; +} +#carbonads span { + display: block; + overflow: hidden; +} +.carbon-img { + display: block; + margin: 0 auto 8px; + line-height: 1; +} +.carbon-text { + display: block; + margin-bottom: 8px; +} +.carbon-poweredby { + display: block; + text-transform: uppercase; + letter-spacing: 1px; + font-size: 9px; + line-height: 1; +} diff --git a/developers/cli_command.html b/developers/cli_command.html new file mode 100644 index 0000000..3a730db --- /dev/null +++ b/developers/cli_command.html @@ -0,0 +1,221 @@ + + + + + CLI Command | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

CLI Command

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Introduction

CLI of hiproxy supplied commands such as start, stop, state and open. If then are not enought, you can add your own ones.

+

You should define something, such as command name, description, handler and options, for the new command. This is description:

+
    +
  • Command Name(command)<String>, i.e. 'hello'
  • +
  • Description(describe)<String>, summary about the command’s usage or more, i.e. 'A test command that say hello to you.'
  • +
  • Usage(usage)<String>, command usage, i.e. 'hello [--name <name>] [-xodD]'
  • +
  • Handler(fn)<Function>, the command invokes the handler while it’s executing. this of the handler refer to a object which describes command line arguments.
  • +
  • Options(option)<Object>, options for the command, supplied in form of key:value. See https://github.com/hemsl/hemsl.
  • +
+

Example

A whole example of custom command is:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
command: 'hello',
describe: 'A test command that say hello to you.',
usage: 'hello [--name <name>] [-xodD]',
fn: function () {
var cliArgs = this;
if (cliArgs.name ) {
console.log('your name is', cliArgs.name.green);
}

if (cliArgs.age ) {
console.log('your are', cliArgs.age.green, 'years old');
}
},
options: {
'name <name>': {
alias: 'n',
describe: 'your name'
},
'age': {
alias: 'a',
describe: 'your age'
}
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/developers/directive.html b/developers/directive.html new file mode 100644 index 0000000..37f7c58 --- /dev/null +++ b/developers/directive.html @@ -0,0 +1,229 @@ + + + + + Rewrite Directive | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite Directive

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Introduction

rewrite directive can configure directive name, scopes and handler. They are:

+
    +
  • Directive Name(name)<String>, i.e. 'add'
  • +
  • Scopes(scope)<Array>, the scopes which the directive runs in. The directive is only valid in specified scopes. The scopes include global, domain, location, request and response.
  • +
  • Handler(fn)<Function>, the handler should be invoked while the directive is execute. See handler for details.
  • +
+

Example

Here is a entire example of directive:

+
1
2
3
4
5
6
7
8
9
10
{
name: 'add',
scope: ['global', 'domain', 'location'],
fn: function (key, a, b) {
var props = this.props;
var value = Number(a) + Number(b);

this.props[key] = value;
}
}
+

+

Handler

The handler is invoked while hiproxy is executing related directive. The parameters whick are specified for the directive in rewrite configuration are passed in and this should be setted.

+

Parameters

The parameters for the directive in rewrite configuration should be passed into handler. For example, proxy_set_header Host hiproxy.org is configured then ('Host', 'hiproxy.org') should be passed into the handler.

+

this

this value is depended on the scope which the directive executs in. Following are possible this values:

+
    +
  • global: the entire rewrite instance - {props: <Object>, domains: <Array>, commands: <Array>}}
  • +
  • domain: domain instance - {domain: <String>, props: <Object>, location: <Array>, commands: <Array>}}
  • +
  • location: location instance - {props: <Object>, location: <String>, commands: <Array>}}
  • +
  • request: {request: <http.IncomingMessage>}
  • +
  • response: {response: <http.ServerResponse>}
  • +
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/developers/index.html b/developers/index.html new file mode 100644 index 0000000..762945f --- /dev/null +++ b/developers/index.html @@ -0,0 +1,210 @@ + + + + + Hiproxy Develpment Guide | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Hiproxy Develpment Guide

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/developers/plugin.html b/developers/plugin.html new file mode 100644 index 0000000..179071c --- /dev/null +++ b/developers/plugin.html @@ -0,0 +1,235 @@ + + + + + Plugin Development Guide | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Plugin Development Guide

+ +
+
+

Hiproxy supplied a mechanism of developing plugins. It’s simple that you need just develop a plugin and install it to global. Hiproxy should look for and load all plugins while it starts.

+

If you want to develop a plugin, hiproxy-plugin-example is a good demo which you can find at https://github.com/hiproxy/hiproxy-plugin-example. This is a entire plugin demo, you can start your own pluign base on the demo.

+

A plugin is a common npm module. You do not need to install hiproxy as a dependency.

+


+

Plugin’s architecture

Three condition should be satisfied before a module becomes a hiproxy pluign:

+
    +
  1. It must be a standalone npm module which export only one object with three properties
  2. +
+
1
2
3
4
5
6
7
8
9
10
module.exports = {
// CLI commands
commands: commands,

// Rewrite config redirectives
directives: directives,

// HTTP server routes
routes: routes
};
+
    +
  • commands: <Array>, extends hiproxy CLI. Each element in the array should be a command configuration. See Command Configuration for details.

    +
  • +
  • directives: <Array>, extends rewrite directive of hiproxy. Each element in the array should be a directive configuration. See Rewrite Directive for details.

    +
  • +
  • routes: <Array>, extends page router of hiproxy. Each element in the array should be a route configuration.See Page Route Configuration for details.

    +
  • +
+
    +
  1. Plugin module must be installed to global

    +
  2. +
  3. Plugin name should use hiproxy-plugin- as prefix

    +
  4. +
+

Code Example

https://github.com/hiproxy/hiproxy-plugin-example/blob/master/index.js#L14-L23

+

Publish Plugin

You can publish a plugin into npm while it’s completed with development and testing.

+

The publish process is the same as publishing other npm module, since the a plugin of hiproxy is jsut a common npm module which follows given rules.

+

Hint

Hiproxy look for plugins which has hiproxy-plugiin- as prefix and installed in the directory described by npm root -g, so that hiproxy cannot find new developing pluigns.

+

npm link can create a symbol link of a plugin so that you can debug it while it’s in development. See npm link of npm document for details.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/developers/route.html b/developers/route.html new file mode 100644 index 0000000..ef13147 --- /dev/null +++ b/developers/route.html @@ -0,0 +1,225 @@ + + + + + Page Route Configuration | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Page Route Configuration

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Introduction

You can visit http://127.0.0.1:<port>/ to watch basic informations of the service after it finished starting.

+

Except that page, hiproxy support a feature for adding new page. For example, plugin hiproxy-plugin-dashboard add a page to hiproxy for showing service information and modifying configuration files, which is at http://127.0.0.1:<port>/dashboard/.

+

Configuration Content

Page route configuration include: route rules and renderer. Then are:

+
    +
  • Route Rules(route):<String>, URL pattern, i.e. '/dashboard(/:page)'. See https://www.npmjs.com/package/url-pattern for details.
  • +
  • Renderer(render):<Function>, for rendering a page. It accept three parameters: (route, request, response).
  • +
+

Renderer, render() Method

render() method should be invokded with three parameters, (route, request, response), while user visit the corresponding page.

+
    +
  • route: <Object>, arguments object from route pattern. For example, /test(/:pageName) pattern cause the object {pageName: 'home'} while /test/home is visiting.
  • +
  • request: <http.IncomingMessage>,http request instance.
  • +
  • response: <http.ServerResponse>,http response instance.
  • +
+

Example

A entire example is below:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
route: '/test(/:pageName)',
render: function (route, request, response) {
   // global variable `hiproxyServer` can be used to get hiproxy server instance.
   response.writeHead(200, {
'Content-Type': 'text/html',
'Powder-By': 'hiproxy-plugin-example'
});

var serverInfo = {
route: route,
pageID: route.pageName,
time: new Date(),
serverState: {
http_port: global.hiproxyServer.httpPort,
https_port: global.hiproxyServer.httpsPort,
cliArgs: global.args,
process_id: process.pid
}
};

response.end('<pre>' + JSON.stringify(serverInfo, null, 4) + '</pre>');
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/faqs/index.html b/faqs/index.html new file mode 100644 index 0000000..768355e --- /dev/null +++ b/faqs/index.html @@ -0,0 +1,238 @@ + + + + + FAQs | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

FAQs

+ +
+
+

What’s the core feature(or purpose) of hiproxy?

The core feature of hiproxy is forwarding request. Hiproxy purposes to solve some problems which front-end developer can meet while working:

+
    +
  • hosts cannot work immediately since there are caches after it’s updated.
  • +
  • Nginx is used for reverse proxy.
  • +
  • Self signed HTTPS certificate are not trusted.
  • +
  • Everyone maintans the environment profile (hosts/nginx configuration).
  • +
  • +
+


+

What’s the difference between hiproxy and Charles/Fiddler?

They all have the ability to capture packages, proxy request and many core function. But hiproxy is a CLI tool which works with configuration files.

+

However, hiproxy has no interface to see the specific content of request. That will be introduced as a plugin in the future.

+


+

What’s the relationship between hosts for hiproxy and for OS?

They are no relationship actually.

+

the hosts file for hiproxy is normally placed in project directory, or other (user specified) directory. Hiproxy would looking for, load and parse the hosts file in project directories, but not do with OS one.

+


+

Is the rewrite configuration file for hiproxy fully compatible with Nginx configuration?

No. They are no relationship actually.

+

The rewrite configuration for rewrite has similar syntax of Nginx configuration. The core syntax is consistent with the syntax of Nginx, but there are also some syntax are specific to hiproxy. They are not exactly consistent with Nginx syntax. For example:

+
1
2
3
4
5
6
7
# base rule
http://hiproxy.org/api/login.do => http://127.0.0.1:9999/api/login.json;

# domain
hiproxy.org => {
# ...
}
+

In addition, some directives come from Nginx which do simular things, such as proxy_pass, set, ssl_certificate and ssl_certificate_key, etc. In any case they cannot promise that all details are same as Nginx directives.Please see Directive for more information.

+


+

Does hiproxy support that the same domain name is used in the configuration files of multi-projects?

It’s supported.

+

You can set rules for the same domain name in configuration files of different projects. Hiproxy can merge all rules about the same domains. If there is conflict, later loaded rules would rewrite earlier rules.

+


+

How does hiproxy handle the conflict between multiple configuraton files?

Some soon.

+


+

How to get/import root certificate of hiproxy?

See get/import SSL certificate

+


+

How hiproxy to use it own SSL certificate?

By default, when the https request is forwading, hiproxy will generate the certifiate automatically and use customized CA certificate signature. The users should import root certificate of hiproxy.

+

If you use customized certificate, ou can use some hiproxy directive for configurating:

+
1
2
ssl_certificate     ./hiproxy.org.crt;
ssl_certificate_key ./hiproxy.org.key;
+


+

+
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/favicon.ico b/favicon.ico new file mode 100644 index 0000000..bc00d59 Binary files /dev/null and b/favicon.ico differ diff --git a/get_started/applied_to_existing_projects.html b/get_started/applied_to_existing_projects.html new file mode 100644 index 0000000..e64487c --- /dev/null +++ b/get_started/applied_to_existing_projects.html @@ -0,0 +1,244 @@ + + + + + Applied to existing projects | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Applied to existing projects

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

1. Global install hiproxy

If you haven’t installed hiproxy,check Installation.

+

All you have to do is to global install hiproxy, Local install is NOT necessary

+

2. Add configuration files

Two rules of ‘hiproxy’:

+
    +
  • All projects in one Workspace;
  • +
  • Put configuration files (hosts / rewrite) into specific project directory, submit them to the repository for version control and teamwork.
  • +
+

Therefore, all configuration files should be located in specific project directory. In terms of different projects, diverse configuration files can be added. While the ‘hiproxy’ on starting, those files will be found from workspace.

+

Recommended directory structure is as follows:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
workspace
├── app-1 # Proj.1
│   ├── hosts # hosts file
│   ├── rewrite # rewrite file
│   └── src # Source code
│   └── ... # other files

├── app-2 # Proj.2
│   ├── hosts # hosts file
│   ├── rewrite # rewrite file
│   └── src # Source code
│   └── ... # other files

└── app-3 # Proj.3
│   ├── hosts # hosts file
│   ├── rewrite # rewrite file
│   └── src # Source code
│   └── ... # other files
+

Of course, to put all configuration files outside of the project directory, just specify the file’s path via the start options:

+
1
2
-c, --hosts-file <files>   hosts files, format: <file1>[,<file2>[,...]]
-r, --rewrite-file <files> rewrite config files, format: <file1>[,<file2>[,...]]
+
+

TIPS

+
    +
  • -c, --hosts-file and -r, --rewrite-file support Simplified pattern matching; e.g. ./*/*.conf;
  • +
  • Supported syntax:*, ?, [abc], [a-z], [^a-z], [!a-z];
  • +
  • Unsupported syntax:**.
  • +
+
+

2.1 Add hosts

hosts is similar to hosts, except it’s located in the project directory, hiproxy will automatically find and resolve the hosts file named ‘hosts’ from the root directory of the project.

+

If the file name isn’t hosts, just specify it via option -c, --hosts-file.

+

You can see hosts for more details.

+

2.2 Add rewrite

rewrite is similar to hosts, it’s also located in the project directory, hiproxy will automatically find and resolve the file named ‘rewrite’ from the root directory of the project.

+

If the file name isn’t rewrite, just specify it via option -r, --rewrite-file.

+

You can see rewrite for more details.

+

3. Git commit

Git commitment is highly recommended, submit configuration files (hosts/rewrite) to the repository for version control and teamwork.

+

4. Start service

The concept of hiproxy is based on Workspace. The proxy service of hiproxy should be started in the workspace. Assuming that all projects are located in ~/workspace/, then this directory is the Workspace.

+

Enter this directory, start the proxy service, then hiproxy will find all the configuration files of all projects.

+

If service is needed before entering the workspace, just start proxy using the option -w, --workspace <workspace> in any directories.

+
1
2
# Enter any directories
hiproxy start -w ~/workspace/
+

TIPS: While on starting the proxy, use the option -o, --open [browser-name] to open a new browser window and configure the proxy automatically. Therefore, no manual configuring is needed.

+

5. Development debugging

When the proxy is started, if the proxy rules are configured, all requests from the browser window will be handled by hiproxy.

+

No need to configure system hosts.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/get_started/cli_options.html b/get_started/cli_options.html new file mode 100644 index 0000000..7bf23d5 --- /dev/null +++ b/get_started/cli_options.html @@ -0,0 +1,223 @@ + + + + + CLI options | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

CLI options

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Command Line Commands and Options

Global Commands

The global hiproxy command without any options will display a welcome message like this:

+
1
2
3
4
5
6
7
> hiproxy
_ _
| | (_)
| |__ _ welcome to use hiproxy
| '_ \| | current version is 1.1.2
| | | | | You can try `hiproxy --help` for more info
|_| |_|_|
+

If you specify the option --help or -h, you will see the complete help information.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
> hiproxy --help

Usage:

hiproxy [command] [option]

Commands:

start Start a local proxy server
stop Stop the local proxy server (Only works in daemon mode)
restart Restart the local proxy service (Only works in daemon mode)
state Show all the servers state (Only works in daemon mode)
open Open browser and set proxy
hello A test command that say hello to you.

Options:

-v, --version Display version information
-h, --help Display help information
--log-dir <dir> The log directory when run in background, default: user home directory
--log-time Show time info before every log message
--log-level The log levels, format: <level1>[,<lavel2[,...]]
--grep <content> Filter the log data
+

start

This command will start a local proxy service on the specified port. You can specify whether the service is running in the background, if running in the background, all the log of the service will be redirect to the log files.

+

The log file is located in the user’s home directory by default. Of course, you can specify the log file’s path via the option --log-dir <dir>.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
> hiproxy start --help

USAGE:

start [--port <port>] [-xodD]

DESCRIBE:

Start a local proxy server

OPTIONS:

-h, --help show help info
-D, --daemon Run hiproxy in background
-c, --hosts-file <files> hosts files, format: <file1>[,<file2>[,...]]
-s, --https Enable HTTPS proxy
-m, --middle-man-port <port> The Man-In-The-MiddleHTTPS proxy port, default: 10010
-o, --open [browser] Open a browser window and use hiproxy proxy
--pac-proxy Use Proxy auto-configuration (PAC)
-p, --port <port> HTTP proxy port, default: 5525
-r, --rewrite-file <files> rewrite config files, format: <file1>[,<file2>[,...]]
--sys-proxy <path> Your own proxy server path, format: <ip>[:port], only works when use PAC
-w, --workspace <dir> The workspace
+

stop

If the proxy service is running in the background, hiproxy provides a stop command to stop the service

+
1
> hiproxy stop
+

open

The open command can open a browser window and automatically set up the browser’s proxy info based on the currently started proxy service.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> hiproxy open --help

USAGE:

open [options]

DESCRIBE:

Open browser and set proxy

OPTIONS:

-h, --help show help info
-b, --browser <browser> Browser name, default: chrome. Valid alues: chrome,firefox,opera
--pac-proxy Use Proxy auto-configuration (PAC)
+

state

This command will display the basic status information of the currently started proxy service.

+

restart

This command will restart the proxy service.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/get_started/index.html b/get_started/index.html new file mode 100644 index 0000000..e9b735b --- /dev/null +++ b/get_started/index.html @@ -0,0 +1,276 @@ + + + + + Introduction | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Introduction

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

hiproxy is a lightweight, extendable network proxy based on Node.js, the main purpose is to resolve the hosts management and proxy request problem that multiple developers encountered in development. And there is no need to modify system hosts and start Nginx service.

+

hiproxy supports hosts file, and the syntax is extended for hosts, it now supports port number. Besides, hiproxy supports configuration file using syntax similar to that for Nginx.

+

Why hiproxy

In front-end development, if developers usually encounter some of the following problems:

+
    +
  1. While debugging online page issues, if both local development and back-end running ability for projects (Node.js/Java project) are required, it may costs a lot for a front-end developer to build a back-end environment locally.
  2. +
  3. If multiple front-end projects exist, with one domain, some projects need to request online resources, other projects request local resources.
  4. +
  5. In order to resolve the cross-domain problems, local development needs to modify Response Header.
  6. +
  7. While developing https site locally, certificate is not trusted.
  8. +
  9. With system hosts changed,it won’t take effect immediately.
  10. +
+

We can use Nginx to resolve the problems above. Nginx is excellent and also a very good friend of our front-end developer. The configuration file style of Nginx is very intuitive, and the configuration efficiency is high.

+

However, when using Nginx, we also need to use hosts to send the related requests to the local Nginx service.

+

In addition, in most cases, the Nginx configuration file will not be submitted to the repository, so other members of the team will copy each others’ configuration file, therefore the efficiency is relatively low, and once a configuration file has been modified, other configuration files will not be updated in time. For the configuration of multiple domains, they are placed in a unified directory, and then being included in the main configuration, which is also inconvenient.

+

hosts, revers proxy, https and cache Will these trivial things be solved in a unified way?

+

So there is hiproxy.

+

Feature

    +
  • Nginx-styled configuration file format supported, configuration is simple and intuitive
  • +
  • Hosts and extensions supported, as well as port number
  • +
  • Plugins extending rewrite commands, CLI commands and page supported
  • +
  • HTTPS certificate auto-generate
  • +
  • Proxy auto-config
  • +
  • Background start and log file output
  • +
  • Configuration file auto-find
  • +
  • Browser window auto-open and proxy auto-config
  • +
  • Node.js API provided
  • +
  • +
+

Concept

After rethought many of the existing development models and summed up some of the encountered problems, hiproxy is developed based on the following two concepts:

+
    +
  • Workspace:hiproxy works in Workspace, the configuration files for all projects in the workspace are resolved by hiproxy. The workspace can be specified via option -w, --workspace <workspace>, or directly into the workspace to start the proxy service.
  • +
  • Shared configuration file: Configuration files are submitted to the repository, and team members share them. Previously, hosts and Nginx configurations were generally not submitted to the repository, and the team members were locally maintained, costly and inefficient.
  • +
+

Basic principle

The core functionality of hiproxy is the proxy request, it handles some of the development details at the same time as the proxy request, such as automatic generation of HTTPS certificates, automatic configuration of browser agents, and so on.

+

The basic principles of hiproxy core functionality describe as follows.

+

Proxy request

hiproxy makes full use of the Man-in-the-middle attack model as intermediaries, data is forwarded at the client and server side to implement the HTTP and proxy for the HTTPS requests.

+

HTTP request

For the HTTP request, if the browser has configured the proxy, it will send GET/POST and so on to the hiproxy agent. After the hiproxy receives the request, it makes some changes to the requested information based on the user’s hosts and rewrite rules, and then goes to the appropriate server to request the resource and return it to the client.

+

HTTPS request

For the HTTPS request, the browser will send a CONNECT request to hiproxy service after the proxy configured, then hiproxy will start a new TCP connection to the final target server (i.e. a new tunnel) and then transmit the data between the client and server.

+

However, it’s only a simple proxy request, and hiproxy cannot obtain the requested information, such as parameters and Cookie, and there is no way to modify the response data. If we do not need to make corresponding changes to the request and response information, this will meet our needs.

+

What needs to be done if we need to implement the same functionality as the HTTP request: do some changes to the request and response based on the requested information?

+

Fortunately, we can make full use of Man-in-the-middle attack model. Because the final target server can get the requested information, we can start an intermediary service between the hiproxy and the final server (here referred to as M), when hiproxy receives a CONNECT request, it starts a new connection to the M, when the M receives the request, it makes some modifications to the request information, like the HTTP request agent, and then requests the resource from the target server and returns it to the client.

+

HTTPS certificate generation

In the SSL/TLS handshake, the first message sent by the client (Client Hello) will be using the extension SNI(Server Name Indication) to send the requested domain to the server. Although only the domain information is sent, other requests, paths, parameters, and cookie are not sent, but the domain is sufficient for the certificate to be generated.

+

When hiproxy gets the domain for the request:

+
    +
  • If the user has configured the certificate for the corresponding domain, the user configured certificate is sent to the client.
  • +
  • Otherwise, a new domain certificate is generated and returned to the client.
  • +
+

Browser window

First, find the path corresponding to the browser in the system. For example, on OSX, look for <browser-name>.app, then start the app and pass arguments to configure the proxy server address.

+
1
<path-to-chrome-app>.app [options] [url]
+

On Windows, you go to the registry to find the exe file path for the browser. Then run and pass arguments.

+
1
<path-to-chrome-app>.exe [options] [url]
+

For Chrome/Opera, we need to pass two arguments:

+
    +
  • Address of proxy service: --proxy-pac-url (PAC proxy file path) or --proxy-server (general agent address), hiproxy supports all.

    +
  • +
  • The directory where user data is stored: --user-data-dir

    +
  • +
+

When passing this argument, and the directory is not the default directory the browser uses to store user data, it will create a new browser instance which is independent of any other browser window and has no effect on each other(the instance has been configured with proxy, the request of other browser instance will not pass through the proxy configuration here).

+

Configuration file

hiproxy can use hosts as a simple proxy request and configure rewrite rules similar to the Nginx syntax for complex configurations.

+

hosts

Consistent with the system hosts syntax, in addition, port numbers are supported. Hosts can only configure the IP and port numbers corresponding to the domain, detailed routing configuration and request response modification are not supported. For more details, check hosts

+

hosts configuration sample

1
2
3
4
5
# comment
127.0.0.1 example.com

# ip + port
127.0.0.1:8800 blog.example.com life.example.com
+

rewrite

The rewrite rule configuration file allows you to use more complex configurations to satisfy complex usage scenarios. You can configure the route in detail and make modifications to the request response. The syntax for the rewrite rule configuration is very similar to that of the Nginx syntax. For more details, check rewrite

+

rewrite configuration sample

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# Global variable
set $port 8899;
set $ip 127.0.0.1;
set $online 210.0.0.0;

# Domain configuration
domain example.com {
location / {
proxy_pass http://$online/;
}

location /blog/ {
proxy_pass http://$ip:$port/blog/;
proxy_set_header from 'hiproxy';
set_header proxy 'hiproxy';
}
}
+

Plugin mechanism

When hiproxy starts, it automatically finds the module at the beginning of the hiproxy-plugin- from the directory in the NPM global module (npm, root, -g) and automatically resolve the plugin content after finding the modules.

+

Therefore, we only need global install plugins independently, no need to upgrade hiproxy, and the hiproxy plugin development is also independent, the plugin project itself is not dependent on hiproxy.

+

For detailed plugin documents, check hiproxy Plugin

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/get_started/installation.html b/get_started/installation.html new file mode 100644 index 0000000..1543212 --- /dev/null +++ b/get_started/installation.html @@ -0,0 +1,223 @@ + + + + + Installation | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Installation

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Install hiproxy

NPM

hiproxy has already been available in npm, install it via commands: +

1
npm install -g hiproxy

+

The latest beta version is also available (might be unstable), install it via commands: +

1
npm install -g hiproxy@beta

+

Install source code from github via commands: +

1
npm install -g hiproxy/hiproxy

+

TIPS: If you haven’t installed NodeJS, download and install it from Node.js

+

YARN

hiproxy can be installed by yarn: +

1
yarn global add hiproxy

+

Plugins installation

hiproxy also supports plugins. The plugins can be installed individually from hiproxy, just global install them.

+

e.g. If you want to install the plugin hiporxy-plugin-dashboard, use the commands below:

+
1
npm install hiproxy-plugin-dashboard -g
+

After installation, the next time hiproxy starts, those plugins will be automatically loaded.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/get_started/run_example.html b/get_started/run_example.html new file mode 100644 index 0000000..464a80f --- /dev/null +++ b/get_started/run_example.html @@ -0,0 +1,237 @@ + + + + + Run Example Project | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Run Example Project

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Introduction

Here is an Example, with a Workspace inside, this workspace contains three basic projects, they use port 8000, 8001 and 8002 respectively.

+

Meanwhile, a script named server.js is provided to start those three services, use command npm start or node start

+

The directory structure of this project is as follows:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.
├── LICENSE
├── README.md
├── package.json
├── start.js # Service start
└── workspace # workspace
├── blog-app # blog app example
│   ├── app.js # express app
│   ├── hosts # hosts file
│   ├── public # static resources
│   └── rewrite # rewrite file
├── main-app # main app example
│   ├── app.js # express app
│   ├── hosts # hosts file
│   └── public # static resources
└── news-app # news app example
├── app.js # express app
└── hosts # hosts file
+

In directory workspace, three apps exist, with a hosts file for each:

+
1
2
# main-app hosts
127.0.0.1:8000 www.example.com
+
1
2
# blog-app hosts
127.0.0.1:8001 blog.example.com
+
1
2
# news-app hosts
127.0.0.1:8002 news.example.com
+

For blog-app, a rewrite file is included:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# rewrite rules
domain blog.example.io {
# rewrite / to 8001;
location / {
proxy_pass http://127.0.0.1:8001/;
}

# static files
location /static/ {
alias ./public/;

set_header server hiproxy;
set_cookie server hiproxy;
}
}
+

+

STEPS

STEP 1: clone codes

The codes of example project is hosted on github, use Git command to clone those codes local

+
1
git clone https://github.com/hiproxy/hiproxy-example.git
+

STEP 2: install dependencies

Enter the root directory of project hiproxy-example/, install all the third-party dependencies

+
1
2
cd hiproxy-example
npm install
+

STEP 3: start service

After cloning codes and installing dependencies, start the service provided by example project. Use command in hiproxy-example/:

+
1
npm start
+

STEP 4: start hiproxy

With all steps above done, start hiproxy to have the first taste of it. Use command in hiproxy-example/:

+
1
hiproxy start --https --open --workspace ./workspace
+

STEP 5: View test page

After running the command above, a browser window will be opened, with proxy already set. Visit any of the links below:

+ + +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/icons/android-touch-icon.png b/icons/android-touch-icon.png new file mode 100644 index 0000000..4fc96f7 Binary files /dev/null and b/icons/android-touch-icon.png differ diff --git a/icons/apple-touch-icon-120x120.png b/icons/apple-touch-icon-120x120.png new file mode 100644 index 0000000..a373d66 Binary files /dev/null and b/icons/apple-touch-icon-120x120.png differ diff --git a/icons/apple-touch-icon-152x152.png b/icons/apple-touch-icon-152x152.png new file mode 100644 index 0000000..9acfa9f Binary files /dev/null and b/icons/apple-touch-icon-152x152.png differ diff --git a/icons/apple-touch-icon-180x180.png b/icons/apple-touch-icon-180x180.png new file mode 100644 index 0000000..6057045 Binary files /dev/null and b/icons/apple-touch-icon-180x180.png differ diff --git a/icons/apple-touch-icon-76x76.png b/icons/apple-touch-icon-76x76.png new file mode 100644 index 0000000..ef1f51b Binary files /dev/null and b/icons/apple-touch-icon-76x76.png differ diff --git a/icons/favicon-160x160.png b/icons/favicon-160x160.png new file mode 100644 index 0000000..0fc3300 Binary files /dev/null and b/icons/favicon-160x160.png differ diff --git a/icons/favicon-16x16.png b/icons/favicon-16x16.png new file mode 100644 index 0000000..f043ca4 Binary files /dev/null and b/icons/favicon-16x16.png differ diff --git a/icons/favicon-196x196.png b/icons/favicon-196x196.png new file mode 100644 index 0000000..780fb27 Binary files /dev/null and b/icons/favicon-196x196.png differ diff --git a/icons/favicon-32x32.png b/icons/favicon-32x32.png new file mode 100644 index 0000000..9d5040c Binary files /dev/null and b/icons/favicon-32x32.png differ diff --git a/icons/favicon-96x96.png b/icons/favicon-96x96.png new file mode 100644 index 0000000..92da766 Binary files /dev/null and b/icons/favicon-96x96.png differ diff --git a/images/android_install_cert_1.png b/images/android_install_cert_1.png new file mode 100644 index 0000000..0bc9979 Binary files /dev/null and b/images/android_install_cert_1.png differ diff --git a/images/android_install_cert_2.png b/images/android_install_cert_2.png new file mode 100644 index 0000000..d80f0f9 Binary files /dev/null and b/images/android_install_cert_2.png differ diff --git a/images/android_install_cert_3.png b/images/android_install_cert_3.png new file mode 100644 index 0000000..025aed5 Binary files /dev/null and b/images/android_install_cert_3.png differ diff --git a/images/hiproxy_start_page.png b/images/hiproxy_start_page.png new file mode 100644 index 0000000..8431c28 Binary files /dev/null and b/images/hiproxy_start_page.png differ diff --git a/images/import_root_cert.png b/images/import_root_cert.png new file mode 100644 index 0000000..c6e60ab Binary files /dev/null and b/images/import_root_cert.png differ diff --git a/images/ios_install_cert_1.jpg b/images/ios_install_cert_1.jpg new file mode 100644 index 0000000..53361f8 Binary files /dev/null and b/images/ios_install_cert_1.jpg differ diff --git a/images/ios_install_cert_2.jpg b/images/ios_install_cert_2.jpg new file mode 100644 index 0000000..5408bbf Binary files /dev/null and b/images/ios_install_cert_2.jpg differ diff --git a/images/ios_install_cert_3.jpg b/images/ios_install_cert_3.jpg new file mode 100644 index 0000000..903e494 Binary files /dev/null and b/images/ios_install_cert_3.jpg differ diff --git a/images/ios_install_cert_4.jpg b/images/ios_install_cert_4.jpg new file mode 100644 index 0000000..a5b5452 Binary files /dev/null and b/images/ios_install_cert_4.jpg differ diff --git a/images/ios_install_cert_5.jpg b/images/ios_install_cert_5.jpg new file mode 100644 index 0000000..fa4f298 Binary files /dev/null and b/images/ios_install_cert_5.jpg differ diff --git a/images/root_cert_trusted.png b/images/root_cert_trusted.png new file mode 100644 index 0000000..f21add5 Binary files /dev/null and b/images/root_cert_trusted.png differ diff --git a/images/trust_root_cert.png b/images/trust_root_cert.png new file mode 100644 index 0000000..c610460 Binary files /dev/null and b/images/trust_root_cert.png differ diff --git a/images/windows_install_cert.png b/images/windows_install_cert.png new file mode 100644 index 0000000..03baf85 Binary files /dev/null and b/images/windows_install_cert.png differ diff --git a/images/windows_install_finish.png b/images/windows_install_finish.png new file mode 100644 index 0000000..3bcd6cb Binary files /dev/null and b/images/windows_install_finish.png differ diff --git a/images/windows_step_1.png b/images/windows_step_1.png new file mode 100644 index 0000000..e12f17a Binary files /dev/null and b/images/windows_step_1.png differ diff --git a/images/windows_step_2.png b/images/windows_step_2.png new file mode 100644 index 0000000..6bafc27 Binary files /dev/null and b/images/windows_step_2.png differ diff --git a/index.html b/index.html new file mode 100644 index 0000000..16179d8 --- /dev/null +++ b/index.html @@ -0,0 +1,182 @@ + + + + + hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+
  • Lightweight & Extensible

    Hiproxy is a lightweight proxy with few dependencies, quick installing, as well as extensible on commands and pages.

  • Keep Your Habits

    Keep used to configure in hosts or Nginx style. Easy to learn, and keep relax in using.

  • Generate Certificate Automatically

    Hiproxy can play the CA role with generated root certificate by itself. It can also generate certificates for each requesting domains.

  • Highly Integrated with Browsers

    While hiproxy starts, it opens a new browser window and configure its proxy automatically. Such you would feel free.

+
    +
  • npm install hiproxy -g
  • +
  • hiproxy init
  • +
  • hiproxy start --open
  • +
+ +
+
+
+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/js/lang_select.js b/js/lang_select.js new file mode 100644 index 0000000..fb7ca06 --- /dev/null +++ b/js/lang_select.js @@ -0,0 +1,15 @@ +(function() { + 'use strict'; + + function changeLang() { + var lang = this.value; + var canonical = this.dataset.canonical; + if (lang === 'en') lang = ''; + if (lang) lang += '/'; + + location.href = '/' + lang + canonical; + } + + document.getElementById('lang-select').addEventListener('change', changeLang); + document.getElementById('mobile-lang-select').addEventListener('change', changeLang); +}()); diff --git a/js/mobile_nav.js b/js/mobile_nav.js new file mode 100644 index 0000000..de54fd6 --- /dev/null +++ b/js/mobile_nav.js @@ -0,0 +1,22 @@ +(function() { + 'use strict'; + + var body = document.getElementsByTagName('body')[0]; + var navToggle = document.getElementById('mobile-nav-toggle'); + var dimmer = document.getElementById('mobile-nav-dimmer'); + var CLASS_NAME = 'mobile-nav-on'; + if (!navToggle) return; + + navToggle.addEventListener('click', function(e) { + e.preventDefault(); + e.stopPropagation(); + body.classList.toggle(CLASS_NAME); + }); + + dimmer.addEventListener('click', function(e) { + if (!body.classList.contains(CLASS_NAME)) return; + + e.preventDefault(); + body.classList.remove(CLASS_NAME); + }); +}()); diff --git a/js/plugins.js b/js/plugins.js new file mode 100644 index 0000000..066f154 --- /dev/null +++ b/js/plugins.js @@ -0,0 +1,66 @@ +(function() { + /* global lunr */ + 'use strict'; + + var elements = document.getElementsByClassName('plugin'); + var $count = document.getElementById('plugin-list-count'); + var $input = document.getElementById('plugin-search-input'); + var elementLen = elements.length; + var index = lunr.Index.load(window.SEARCH_INDEX); + + function updateCount(count) { + $count.innerHTML = count + (count === 1 ? ' item' : ' items'); + } + + function addClass(elem, className) { + var classList = elem.classList; + + if (!classList.contains(className)) { + classList.add(className); + } + } + + function removeClass(elem, className) { + var classList = elem.classList; + + if (classList.contains(className)) { + classList.remove(className); + } + } + + function search(value) { + var result = index.search('*' + value + '*'); + var len = result.length; + var selected = {}; + var i = 0; + + for (i = 0; i < len; i++) { + selected[result[i].ref] = true; + } + + for (i = 0; i < elementLen; i++) { + if (selected[i]) { + addClass(elements[i], 'on'); + } else { + removeClass(elements[i], 'on'); + } + } + + updateCount(len); + } + + function displayAll() { + for (var i = 0; i < elementLen; i++) { + addClass(elements[i], 'on'); + } + + updateCount(elements.length); + } + + $input.addEventListener('input', function() { + var value = this.value; + + if (!value) return displayAll(); + search(value); + }); +}()); diff --git a/js/toc.js b/js/toc.js new file mode 100644 index 0000000..8574ed0 --- /dev/null +++ b/js/toc.js @@ -0,0 +1,31 @@ +(function() { + 'use strict'; + + var header = document.getElementById('header'); + var toc = document.getElementById('article-toc'); + var tocTop = document.getElementById('article-toc-top'); + var headerHeight = header.clientHeight; + + if (!toc) return; + + function updateSidebarPosition() { + var scrollTop = document.scrollingElement.scrollTop; + + if (scrollTop > headerHeight) { + toc.classList.add('fixed'); + } else { + toc.classList.remove('fixed'); + } + } + + window.addEventListener('scroll', function() { + window.requestAnimationFrame(updateSidebarPosition); + }); + + updateSidebarPosition(); + + tocTop.addEventListener('click', function(e) { + e.preventDefault(); + document.scrollingElement.scrollTop = 0; + }); +}()); diff --git a/logo-light.svg b/logo-light.svg new file mode 100644 index 0000000..c9687ba --- /dev/null +++ b/logo-light.svg @@ -0,0 +1,54 @@ + + + + hiproxy-logo + Created with Sketch. + + + + + + + \ No newline at end of file diff --git a/logo.png b/logo.png new file mode 100644 index 0000000..8723597 Binary files /dev/null and b/logo.png differ diff --git a/logo.svg b/logo.svg new file mode 100644 index 0000000..a48265f --- /dev/null +++ b/logo.svg @@ -0,0 +1,54 @@ + + + + hiproxy-logo + Created with Sketch. + + + + + + + \ No newline at end of file diff --git a/news/2018/10/index.html b/news/2018/10/index.html new file mode 100644 index 0000000..bb91838 --- /dev/null +++ b/news/2018/10/index.html @@ -0,0 +1,169 @@ + + + + + News | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+ + + + + + +
+
+
+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/news/2018/index.html b/news/2018/index.html new file mode 100644 index 0000000..915162a --- /dev/null +++ b/news/2018/index.html @@ -0,0 +1,169 @@ + + + + + News | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+ + + + + + +
+
+
+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/news/index.html b/news/index.html new file mode 100644 index 0000000..88b9ce2 --- /dev/null +++ b/news/index.html @@ -0,0 +1,169 @@ + + + + + News | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+ + + + + + +
+
+
+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/placeholder b/placeholder deleted file mode 100644 index e69de29..0000000 diff --git a/rewrite/built_in_variable.html b/rewrite/built_in_variable.html new file mode 100644 index 0000000..9a620ef --- /dev/null +++ b/rewrite/built_in_variable.html @@ -0,0 +1,234 @@ + + + + + Rewrite Built-in Variables | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite Built-in Variables

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

You can define your own global variables (use set $var value in global scope) in rewrite rules configuration file of hiproxy, as well as you can define variables in other scopes.

+

Hiproxy has some built-in variables so that you can use them directly in corresponding scopes without neither defining nor assigning. Particularly, user cannot redefine the variables to overwrite them.

+

Global variables

Global variables can be used in everywhere of configuration files.

+
+

Hint: hiproxy currently has not built-in variables. Some would be added in the furture.

+
+

Location block scope variables

You can use the variables only in location blocks. Then are used to store information about request, such as query string($query_string), Cookie($cookie_name), and host($host), etc. Here are all the variables that are currently supported:

+

$host

The host correlative to the current request URL, or the Host field in request headers.

+

$hostname

The hostname correlative to the current request URL, or correlative to the Host field in request headers.

+

$server_port

The server port number of the request, default 80.

+

$search

The query string (with ?) of the request, such as ?from=app&v=19482848253.

+

$query_string

The query string (without ?), such as from=app&v=19482848253.

+

$scheme

The request protocol, it’s either http or https.

+

$request_uri

The entire request URL, such as http://hiproxy.org:8081/docs/index.html?from=google&v=_1847295727524#get-started.

+

$path

The request path (with query string), such as /docs/index.html?from=google&v=_1847295727524#get-started.

+

$path_name

The request path_name (without query string), such as /docs/index.html.

+

$base_name

The last part of the path. For exampke, let’s say the path is /docs/index.html, so that $base_name is index.html.

+

$dir_name

The directory names of the path. For example, let’s say path is /docs/index.html, so that $dir_name is /docs/.

+

$hash

The hash (with #) of request URL, such as #get-started.

+

$hash_value

The hash value (without #) of request URL, such as get-started.

+

$uri

Same as $request_uri.

+

$cookie_name

A cookie value. The name stands field name whose capital letters have been changed to lower ones and - characters have been changed to _. For example, $cookie_userId is for the value of userId in the cookie.

+

$http_name

The value of a request header field. The name stands field name whose capital letters have been changed to lower ones and - characters have been changed to _. For example, let’s say User-Agent: user agent is a valid request header, then $http_user_agent can get its value.

+

$arg_name

The value of a request query parameter. The name stands field name whose capital letters have been changed to lower ones and - characters have been changed to _. For example, let’s say the query string is ?from=google&v=_1847295727524, then$arg_fromcan get value offrom`.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/rewrite/directives.html b/rewrite/directives.html new file mode 100644 index 0000000..ed3d288 --- /dev/null +++ b/rewrite/directives.html @@ -0,0 +1,359 @@ + + + + + Rewrite Directive | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite Directive

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+ + +

Directive

directive(known as command)is for setting variable, or manipulating request/response.

+

Global Directives

* set

Description: define variables

+

Syntax:

+
+

set key value

+
+

Scope Chain:global, domain, location

+

Example:

+
1
set $server hiipack;
+

Request Directives

The directives are Request instances to send request from proxy to target server.

+

Scope Chain:domain, location

+

* proxy_set_header

Description: setting a request header

+

Syntax:

+
+

proxy_set_header key value

+
+

Example:

+
1
proxy_set_header Host some.example.com;
+

* proxy_hide_header

Description: remove a request header

+

Syntax:

+
+

proxy_hide_header key

+
+

Example:

+
1
proxy_hide_header Host;
+

* proxy_set_cookie

Description: setting a request cookie value

+

Syntax:

+
+

proxy_set_cookie key value

+
+

Example:

+
1
proxy_set_cookie from hiproxy;
+

* proxy_hide_cookie

Description: remove a request cookie value

+

Syntax:

+
+

proxy_hide_cookie key

+
+

Example:

+
1
proxy_hide_cookie from;
+

* proxy_method

Description: set the request method.

+

Syntax:

+
+

proxy_method method

+
+

Example:

+
1
proxy_method POST;
+

* proxy_set_body

Description: set the request body content.

+

Syntax:

+
+

proxy_set_body body

+
+

Example:

+
1
proxy_set_body "a=1&b=2&c=3";
+

* proxy_append_body

Description: append content to the body.

+

Syntax:

+
+

proxy_append_body content

+
+

Example:

+
1
proxy_append_body "&d=4";
+

* proxy_replace_body

Description: replace part of the body.

+

Syntax:

+
+

proxy_replace_body oldVal newVal

+
+

Example:

+
1
proxy_replace_body "a=1" "a=111";
+

Response directives

The directives are Response instances to let proxy response the browser.

+

Scope Chain:domain, location

+

* status

Description: Set the response status code and status message.

+

Syntax:

+
+

status statusCode statusMessage

+
+

Example:

+
1
status 477 "Authentication failed";
+

* set_header

Description: add a header

+

Syntax:

+
+

set_header key value

+
+

Example:

+
1
set_header SERVER hiproxy;
+

* hide_header

Description: remove a header

+

Syntax:

+
+

hide_header key

+
+

Example:

+
1
hide_header SERVER;
+

* set_cookie

Description: set a coolie value

+

Syntax:

+
+

set_cookie key value

+
+

Example

+
1
set_cookie SESSION_ID 2BF36A09CB35FD71E;
+

* hide_cookie

Description: remove a cookie value

+

Syntax:

+
+

hide_cookie key

+
+

Example:

+
1
hide_cookie SESSION_ID;
+

* send_file

Description: send the specified file as response

+

Syntax:

+
+

send_file file_name

+
+

Example:

+
1
2
send_file index.html;
send_file /site/index.html;
+

* echo

Description: response specified content

+

Syntax:

+
+

echo string

+
+

Example:

+
1
2
echo <h1>hello_echo</h1>;
echo <p>finish</p>;
+

Directives in domain

They are valid only in then same domain and make directives ignored which has the same name in global scope.

+

Scope Chain:domain

+

* ssl_certificate

Description: specify certificate file

+

parameter: ssl_certificate file.crt

+

Example:

+
1
2
3
example.com => {
ssl_certificate /user/root/.hiproxy/cert/example.crt;
}
+

* ssl_certificate_key

Description: specify the file storing private key

+

parameter: ssl_certificate_key file.key

+

Example:

+
1
2
3
example.com => {
ssl_certificate_key /user/root/.hiproxy/cert/example.key;
}
+

Directives in location

They are valid only in the same location and make directives ignored which has the same name in global scope.

+

Scope Chain:domain, location

+

* proxy_pass

Description: set the target location of forwarding

+

parameter: proxy_pass url

+

Example:

+
1
proxy_pass http://some.example.com/some/path/;
+

* alias

Description: map the particular location to native.

+

parameter: alias path

+

Example:

+
1
alias /Users/root/some/path/;
+

* root

Description: the default document while location is mapped to native. index.html is the omitted document name.

+

parameter: root file_name

+

Example:

+
1
root app.html;
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/rewrite/index.html b/rewrite/index.html new file mode 100644 index 0000000..f0c5a43 --- /dev/null +++ b/rewrite/index.html @@ -0,0 +1,247 @@ + + + + + Rewrite Introduction | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite Introduction

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Introduction

rewrite reference Nginx configuration syntax. With very simple configuration, it is helpful for front-end developer to debug in native with online API or some other environemnts.

+

The server would scan and monitor rewrite files in each projects while it’s running. If some file are changed, it can update forward rules immediately without restarting the server.

+

Note: hiproxy support both rewrite and hosts file. If you need only simple domain+port forwarding, you can use host file by referencinghosts.

+

Basic syntax

Variables

Syntax +

1
$variableName

+

Example

+
1
2
3
4
5
# 定义变量
set $var_name value

# 使用变量
$var_name
+

domain

domain specify a domain name and all configuration about the domain name should be in the domain block.

+

Syntax

+
1
2
3
[domain_name|variable] => {
# ...
}
+

Example

+
1
2
3
4
5
6
7
8
9
10
11
set $domain some.example.com

# use a domain name directly
some.example.com => {
# ...
}

# or use a variable
$domain => {
# ...
}
+

Or

+
1
2
3
4
5
6
7
8
9
10
11
set $domain some.example.com

# use a domain name directly
domain some.example.com {
# ...
}

# or use a variable
domain $domain {
# ...
}
+

location

location represent a specific path. All configuration about the path should be in the location block.

+

Note: location must be in domain block.

+

Syntax

+
1
2
3
location [directory|file|regex|variables] {
# ...
}
+

Example

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# directory
location /some/path/ {
# ...
}

# specific file
location /some/file.htm {
# ...
}

# regular expression
location ~ ^/some/(path|path1)/.* {
# ...
}

# variables
location $some/$path {
# ...
}
+

Directives

Directive is used to set variables, or manipulate request/response.

+

Syntax

+
1
command param1 param2 ... paramN
+

Example

+
1
2
3
4
5
# set proxy header
proxy_set_header Host some.example.com;

# set cookie in response
set_cookie UserID some_user_id;
+

Comments

Annotate certain unnecessary conent Only line comments are supported.

+

Syntax

+
1
# comment content
+

Brief syntax

The brief syntax can define some basic rules, no need location or other directives.

+

Syntax

+
1
domain => domain|path
+

Example

+
1
json.example.com => 127.0.0.1:8800;
+

More Examples

1
2
3
4
5
set $local 127.0.0.1:8800
# simple rewrite rule
api.hiproxy.org => local.hiproxy.org;
api.hiproxy.org => 127.0.0.1:8800;
api.hiproxy.org/mock => $local/mock;
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# rewrite folder
api.hiproxy.org/user/ => {
proxy_pass local.hiproxy.org/user/;

# proxy request config
proxy_set_header Host api.hiproxy.org;
proxy_set_header other value;
proxy_hide_header other;

proxy_set_cookie userid 20150910121359;
proxy_hide_cookie sessionid;

# response config
set_cookie sessionID E3BF86A90ACDD6C5FF49ACB09;
set_header proxy hiproxy;

# allow CORS
set_header Access-Control-Allow-Origin *;

hide_header proxy;
hide_cookie sessionID;
}
+
1
2
3
4
# regexp support
~ /(demo|example)/([^\/]*\.(html|htm))$ => {
proxy_pass http://127.0.0.1:9999/$1/src/$2;
}
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
set $domain api.hiproxy.org;
set $local 127.0.0.1:8800;
set $api api;
set $test $api.example.com;
set $id 1234567;

# standard rewrite url
$domain => {
proxy_pass http://$local/api/mock/;
set $id 1234;
set $mock_user user_$id;
set_header Host $domain;
set_header UserID $mock_user;
set_header Access-Control-Allow-Origin *;
}

blog.hiproxy.org => {
set_header Access-Control-Allow-Origin *;

set $node_server 127.0.0.1:3008;
set $order order;
set $cookie1 login=true;expires=20160909;

location /$api/$order/detail {
proxy_pass http://$node_server/user/?domain=$domain;
set_header Set-Cookie userID 200908204140;
}

location ~ /(usercenter|userinfo)/ {
set $cookie login=true;expires=20180808;
set $id 56789;

proxy_pass http://127.0.0.1:3008/info/;

set_cookie userID 200908204140;
set_cookie userName user_$id;
}

location ~ /local/(.*)(\?(.*))? {
send_file ./mock/$1.json;
}

location /dev {
#alias /site/path/;
alias ./src/view/;
root app.html
}

location /multiple {
echo <h1>hello_echo</h1>;
echo <p>test echo directive</p>;
echo <p>finish</p>;
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/rewrite/scope.html b/rewrite/scope.html new file mode 100644 index 0000000..3c07fff --- /dev/null +++ b/rewrite/scope.html @@ -0,0 +1,236 @@ + + + + + Rewrite Scope | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite Scope

+ +
+
+
+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Code block

There are three categories of code block in hiproxy:

+
    +
  • global block: All configurations which are not in other blocks, are in global block;
  • +
  • domain block: It’s nested in global block;
  • +
  • location block: It’s nested in domain block;
  • +
+

Scope

There are five types of scopes that are involved in the configuration file:

+
    +
  • global scope: The scope is corresponding to global block. The variables in the global scope can be accessed everywhere;
  • +
  • domain scope: The scope is corresponding to domain block.
  • +
  • location scope: The scope is corresponding to location block.
  • +
  • request scope: A implicit scopre which is not corrsponding to any code block. The directives in the scope are distributed across any code block.
  • +
  • response scope: A implicit scopre which is not corrsponding to any code block. The directives in the scope are distributed across any code block.
  • +
+

Code block hierarchy

1
2
3
4
5
6
7
8
9
global
|- domain
|- location
|- location
|- ...
|- domain
|- location
|- location
|- ...
+

Looking for variables

Here are rules for looking for variables in current scope:

+
    +
  1. While the varialbe is in current scope, its value should be returned.
  2. +
  3. Looking for the varialbe in upper level scope, and return the value if it’s found.
  4. +
  5. Otherwise, if upper scope is global scope, the variable name (include $ character) should be returned.
  6. +
  7. Repeat steps [2-3].
  8. +
+

Execute directive

The directive in the code block executes automaticlly at the appropriate time (request/response). The directives in upper scope execute too.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
www1.test.com => {
# 1
proxy_set_header Host www.test.com;

location / {
# 2
proxy_pass http://52.88.88.88/;
}

location /index.html {
# 3
proxy_pass http://127.0.0.1:8800/girl/view/index.html;
}

location ~ /\/(native|gallery|picture|font)\/(.*)/ {
# 4
proxy_pass http://88.88.88.88/$1/$2;
}
}
+

In the configuration, if the directive at #2, #3 or #4 executes, the one at #1 would execute too. That means:

+

A request for /, /index.html or /\/(native|gallery|picture|font)\/(.*)/ should be add a Host header, which has www.test.com as value.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/sitemap.xml b/sitemap.xml new file mode 100644 index 0000000..1214ad9 --- /dev/null +++ b/sitemap.xml @@ -0,0 +1,333 @@ + + + + + http://hiproxy.org/zh-cn/rewrite/index.html + + 2018-10-19T09:50:30.334Z + + + + + http://hiproxy.org/zh-cn/rewrite/directives.html + + 2018-10-19T09:50:30.334Z + + + + + http://hiproxy.org/zh-cn/rewrite/scope.html + + 2018-10-19T09:50:30.334Z + + + + + http://hiproxy.org/zh-cn/rewrite/built_in_variable.html + + 2018-10-19T09:50:30.333Z + + + + + http://hiproxy.org/zh-cn/index.html + + 2018-10-19T09:50:30.333Z + + + + + http://hiproxy.org/zh-cn/get_started/installation.html + + 2018-10-19T09:50:30.326Z + + + + + http://hiproxy.org/zh-cn/get_started/cli_options.html + + 2018-10-19T09:50:30.326Z + + + + + http://hiproxy.org/zh-cn/get_started/applied_to_existing_projects.html + + 2018-10-19T09:50:30.326Z + + + + + http://hiproxy.org/zh-cn/get_started/run_example.html + + 2018-10-19T09:50:30.326Z + + + + + http://hiproxy.org/zh-cn/get_started/index.html + + 2018-10-19T09:50:30.326Z + + + + + http://hiproxy.org/zh-cn/developers/route.html + + 2018-10-19T09:50:30.325Z + + + + + http://hiproxy.org/zh-cn/developers/plugin.html + + 2018-10-19T09:50:30.325Z + + + + + http://hiproxy.org/zh-cn/developers/directive.html + + 2018-10-19T09:50:30.325Z + + + + + http://hiproxy.org/zh-cn/faqs/index.html + + 2018-10-19T09:50:30.325Z + + + + + http://hiproxy.org/zh-cn/developers/index.html + + 2018-10-19T09:50:30.325Z + + + + + http://hiproxy.org/zh-cn/developers/cli_command.html + + 2018-10-19T09:50:30.324Z + + + + + http://hiproxy.org/zh-cn/configuration/ssl_certificate.html + + 2018-10-19T09:50:30.324Z + + + + + http://hiproxy.org/zh-cn/configuration/rewrite.html + + 2018-10-19T09:50:30.323Z + + + + + http://hiproxy.org/zh-cn/configuration/index.html + + 2018-10-19T09:50:30.323Z + + + + + http://hiproxy.org/zh-cn/api/index.html + + 2018-10-19T09:50:30.322Z + + + + + http://hiproxy.org/zh-cn/configuration/hosts.html + + 2018-10-19T09:50:30.322Z + + + + + http://hiproxy.org/zh-cn/configuration/find_conf.html + + 2018-10-19T09:50:30.322Z + + + + + http://hiproxy.org/zh-cn/api/events.html + + 2018-10-19T09:50:30.321Z + + + + + http://hiproxy.org/rewrite/scope.html + + 2018-10-19T09:50:30.320Z + + + + + http://hiproxy.org/rewrite/index.html + + 2018-10-19T09:50:30.320Z + + + + + http://hiproxy.org/rewrite/built_in_variable.html + + 2018-10-19T09:50:30.319Z + + + + + http://hiproxy.org/rewrite/directives.html + + 2018-10-19T09:50:30.319Z + + + + + http://hiproxy.org/index.html + + 2018-10-19T09:50:30.318Z + + + + + http://hiproxy.org/get_started/run_example.html + + 2018-10-19T09:50:30.302Z + + + + + http://hiproxy.org/get_started/installation.html + + 2018-10-19T09:50:30.301Z + + + + + http://hiproxy.org/get_started/index.html + + 2018-10-19T09:50:30.301Z + + + + + http://hiproxy.org/get_started/applied_to_existing_projects.html + + 2018-10-19T09:50:30.301Z + + + + + http://hiproxy.org/get_started/cli_options.html + + 2018-10-19T09:50:30.301Z + + + + + http://hiproxy.org/faqs/index.html + + 2018-10-19T09:50:30.300Z + + + + + http://hiproxy.org/developers/index.html + + 2018-10-19T09:50:30.299Z + + + + + http://hiproxy.org/developers/plugin.html + + 2018-10-19T09:50:30.299Z + + + + + http://hiproxy.org/developers/route.html + + 2018-10-19T09:50:30.299Z + + + + + http://hiproxy.org/developers/directive.html + + 2018-10-19T09:50:30.299Z + + + + + http://hiproxy.org/developers/cli_command.html + + 2018-10-19T09:50:30.298Z + + + + + http://hiproxy.org/configuration/ssl_certificate.html + + 2018-10-19T09:50:30.298Z + + + + + http://hiproxy.org/configuration/rewrite.html + + 2018-10-19T09:50:30.298Z + + + + + http://hiproxy.org/configuration/index.html + + 2018-10-19T09:50:30.297Z + + + + + http://hiproxy.org/configuration/hosts.html + + 2018-10-19T09:50:30.297Z + + + + + http://hiproxy.org/configuration/find_conf.html + + 2018-10-19T09:50:30.297Z + + + + + http://hiproxy.org/api/index.html + + 2018-10-19T09:50:30.296Z + + + + + http://hiproxy.org/api/events.html + + 2018-10-19T09:50:30.295Z + + + + + http://hiproxy.org/2014-07-13-test/ + + 2018-10-19T09:50:30.295Z + + + + diff --git a/zh-cn/CNAME b/zh-cn/CNAME new file mode 100644 index 0000000..8162ad7 --- /dev/null +++ b/zh-cn/CNAME @@ -0,0 +1 @@ +hiproxy.org \ No newline at end of file diff --git a/zh-cn/api/events.html b/zh-cn/api/events.html new file mode 100644 index 0000000..003c4f2 --- /dev/null +++ b/zh-cn/api/events.html @@ -0,0 +1,310 @@ + + + + + Events | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Events

+ +
+
+

ProxyServer ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

+ +

+

“start”

Emitted when the hiproxy server(s) start.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| servers | Array | http/https server | +| localIP | String | the local ip address |

+

+

“stop”

Emitted when the hiproxy server(s) stop.

+

Kind: event emitted by ProxyServer

+

“addHostsFile”

Emitted when add hosts file.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| filePath | Array \| String | rewrite file path(s) |

+

+

“addRewriteFile”

Emitted when add rewrite file.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| filePath | Array \| String | rewrite file path(s) |

+

+

“creatPacFile”

Emitter when the pac proxy file is created or updated.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| domains | Object | domain list |

+

+

“httpsRequest”

Emitted each time there is a request to the https server.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request object | +| response | http.ServerResponse | response object |

+

+

“connect”

Emitted each time the server responds to a request with a CONNECT method.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request object | +| socket | net.Socket | socket object | +| head | Buffer | head |

+

+

“setResponse”

Emitted each time the server set response info (eg: headers).

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| response | http.ServerResponse | request object |

+

+

“request”

Emitted each time there is a request.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request object | +| response | http.ServerResponse | response object |

+

+

“getProxyInfo”

Emitted each time the hiproxy server get proxy info for current request.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| proxyInfo | Object | proxy info object |

+

+

“setRequest”

Emitted each time the hiproxy server set request options (eg: headers and host) before request data from remote server

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| request | http.IncomingMessage | request | +| proxyOptions | Object | the proxy header options |

+

+

“setResponse”

Emitted each time the server set response info (eg: headers).

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| response | http.ServerResponse | request object |

+

+

“data”

Emitted whenever the response stream received some chunk of data.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| data | Buffer | response data |

+

+

“response”

Emitted when a response is end. This event is emitted only once.

+

Kind: event emitted by ProxyServer
Properties

+

| Name | Type | Description | +| — | — | — | +| response | http.ServerResponse | response object |

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/api/index.html b/zh-cn/api/index.html new file mode 100644 index 0000000..c48b957 --- /dev/null +++ b/zh-cn/api/index.html @@ -0,0 +1,279 @@ + + + + + Node.js API | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Node.js API

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

+

ProxyServer ⇐ EventEmitter

Kind: global class
Extends: EventEmitter

+ +

+

new ProxyServer(httpPort, httpsPort)

hiproxy代理服务器

+

| Param | Type | Description | +| — | — | — | +| options | Object | 配置参数 | +| options.httpPort | Number | http代理服务端口号,如果传递0/null/undefined,将会自动分配一个可用端口号 | +| options.httpsPort | Number | https代理服务端口号,如果传递0,将会自动分配一个可用端口号,如果传递null或者undefined,不启动https服务。 | +| [options.dir] | String | hiproxy工作空间,默认为当前工作目录(process.cwd()) |

+

+

proxyServer.start([config]) ⇒ Promise

启动代理服务

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Description | +| — | — | — | +| config | Object | 配置字段 |

+

+

proxyServer.stop() ⇒ ProxyServer

停止代理服务

+

Kind: instance method of ProxyServer
Access: public

+

proxyServer.restart() ⇒ ProxyServer

重启代理服务

+

Kind: instance method of ProxyServer
Access: public

+

proxyServer.addHostsFile(filePath) ⇒ ProxyServer

添加Hosts文件

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Description | +| — | — | — | +| filePath | String \| Array | hosts文件路径(绝对路径) |

+

+

proxyServer.addRewriteFile(filePath) ⇒ ProxyServer

添加rewrite文件

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Description | +| — | — | — | +| filePath | String \| Array | rewrite文件路径(绝对路径) |

+

+

proxyServer.openBrowser(browserName, url, [usePacProxy]) ⇒ ProxyServer

打开浏览器窗口

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Default | Description | +| — | — | — | — | +| browserName | String | | 浏览器名称 | +| url | String | | 要打开的url | +| [usePacProxy] | Boolean | false | 是否使用自动代理 |

+

+

proxyServer.enableConfFile(confFileType, filePath) ⇒ ProxyServer

启用指定配置文件

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Default | Description | +| — | — | — | — | +| confFileType | String | | 文件类型(host/rewrite) | +| filePath | String \| Array | | 修改的文件路径 |

+

+

proxyServer.disableConfFile(confFileType, filePath) ⇒ ProxyServer

禁用指定配置文件

+

Kind: instance method of ProxyServer
Access: public

+

| Param | Type | Default | Description | +| — | — | — | — | +| confFileType | String | | 文件类型(host/rewrite) | +| filePath | String \| Array | | 修改的文件路径 |

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/configuration/find_conf.html b/zh-cn/configuration/find_conf.html new file mode 100644 index 0000000..14de1ff --- /dev/null +++ b/zh-cn/configuration/find_conf.html @@ -0,0 +1,235 @@ + + + + + 配置文件查找 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

配置文件查找

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

如果是遵循hiproxy的理念的存放配置文件(包括配置文件的文件名),当hiproxy的启动时,能够自动查找项目的配置文件,不需要手动指定配置文件。

+

如果没有遵循,把配置文件存放在其他路径或者不是使用默认的文件名称(hosts文件默认文件名称为hosts,rewrite文件默认的文件名称为rewrite),需要在启动的时候,手动指定配置文件名称。

+

指定配置文件

要指定配置文件名称,可以使用选项-c, --hosts-file <files>-r, --rewrite-file <files>

+

-c, --hosts-file <files>用来指定hosts的文件路径,多个文件使用,分隔。

+

-r, --rewrite-file <files>用来指定rewrite的文件路径,多个文件使用,分隔。

+

<files>也支持使用简单的通配符模式来指定多个文件,比如--rewrite-file ./*/*.conf

+
+

注意

+

如果指定了对应的配置文件,hiproxy会查找指定的文件,不再查找默认的hosts或者rewrite,比如: + 指定了`-c .//hosts.conf,则不再查找名称为hosts的文件。 +* 指定了-r ./*/rewrite.conf,则不再查找名称为rewrite`的文件。

+
+

配置文件名称通配符

支持的通配符有:

+

通配符 | 说明 | 示例 | 匹配 | 不匹配 +———|———-|———|———-|——— + * | 匹配一个或者多个字符 | ./test-*.js | ./test-hello.js | ./test-.js + ? | 匹配一个字符 | ./test?.js | ./testA.js | ./testAB.js + [abc] | 匹配方括号的中任意字符。 | ./test[ABC].js | ./testA.js | ./testD.js + [^abc] | 匹配非方括号的中任意字符。 | ./test[^ABC].js | ./testD.js | ./testA.js + [!abc] | 同[^abc] | ./test[!ABC].js | ./testD.js | ./testA.js

+
+

注意

+

不支持使用**来查找任意层级目录中的文件。

+
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/configuration/hosts.html b/zh-cn/configuration/hosts.html new file mode 100644 index 0000000..2ccc421 --- /dev/null +++ b/zh-cn/configuration/hosts.html @@ -0,0 +1,222 @@ + + + + + Hosts | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Hosts

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

简介

Hosts 可以看作一个增强版的系统hosts,其最大特性是可以支持端口转发

+

:hiproxy同时支持项目hosts及[rewrite][rewrite]文件。hosts仅支持简单的域名转发,如果需要设置高级域名转发规则,请参考[rewrite][../rewrite/]。

+

工作机制

hiproxy 启动时,会读取并解析各项目根目录中的hosts文件,代理服务器接收到请求后,会根据hosts文件做相应文请求的转发。

+

特性

    +
  • 支持端口转发;
  • +
  • 使用项目hosts文件,不会有系统自带hosts的缓存问题;
  • +
  • 修改项目hosts文件后,不需要重启hiproxy,hiproxy会自动自动更新hosts规则。
  • +
+

语法

语法跟系统hosts语法基本一致,唯一区别是hiproxy的hosts支持IP+端口,语法如下:

+
1
IP[:端口] 域名1 域名2 域名3 ... 域名N
+

例子

1
2
3
4
# custom hosts with port :)

127.0.0.1:8800 hiproxy.org blog.hiproxy.org
127.0.0.1 hiproxy.org blog.hiproxy.org
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/configuration/index.html b/zh-cn/configuration/index.html new file mode 100644 index 0000000..b0bfb93 --- /dev/null +++ b/zh-cn/configuration/index.html @@ -0,0 +1,233 @@ + + + + + 简介 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

简介

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

配置文件类型

hiproxy可以使用hosts来做简单的请求代理,对于复杂的配置使用跟Nginx语法类似的rewrite规则配置。

+

hosts

跟系统hosts语法一致,此外也支持端口号。hosts只能配置域名对应的ip和端口号,不支持详细的路由配置以及对请求响应做修改。更多详细信息请查看hosts

+

hosts配置示例

1
2
3
4
5
# comment
127.0.0.1 example.com

# ip + port
127.0.0.1:8800 blog.example.com life.example.com
+

rewrite

rewrite规则配置文件,可以使用更复杂的配置、满足复杂的使用场景。可以对路由进行详细的配置以及对请求响应做修改。rewrite配置的语法,跟Nginx语法非常类似。更多详细信息请查看rewrite

+

rewrite配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 全局变量
set $port 8899;
set $ip 127.0.0.1;
set $online 210.0.0.0;

# 域名配置
domain example.com {
location / {
proxy_pass http://$online/;
}

location /blog/ {
proxy_pass http://$ip:$port/blog/;
proxy_set_header from 'hiproxy';
set_header proxy 'hiproxy';
}
}
+

配置文件位置

hiproxy推荐把配置文件存放在具体的项目根目录(hosts文件名称为hosts,rewrite配置文件名称为rewrite),项目位于工作空间中,也就是类似如下结构:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
workspace
├── app-1 # 项目1
│   ├── hosts # hosts文件
│   ├── rewrite # rewrite文件
│   └── src # 项目代码
│   └── ... # 其他文件

├── app-2 # 项目2
│   ├── hosts # hosts文件
│   ├── rewrite # rewrite文件
│   └── src # 项目代码
│   └── ... # 其他文件

└── app-3 # 项目3
├── hosts # hosts文件
├── rewrite # rewrite文件
└── src # 项目代码
   └── ... # 其他文件
+

这样的好处在于,这些配置文件可以提交代码仓库,团队成员共享,节约维护成本。hiproxy也能自动查找这些文件。

+

配置文件查找

如果是遵循上面的规则存放配置文件(包括配置文件的文件名),当hiproxy的工作空间为workspace目录时,能够自动查找到上面三个项目的配置文件,不需要手动指定配置文件。

+

如果没有遵循上面的规则,把配置文件存放在其他路径或者不是使用默认的文件名称(hosts文件默认文件名称为hosts,rewrite文件默认的文件名称为rewrite),需要在启动的时候,手动指定配置文件名称。

+

详情请查看配置文件查找

+

配置文件更新

hiproxy支持两种代理方式:PAC(Proxy-Auto-Config)和普通代理。

+

默认情况下使用普通代理,启动时添加选项--pac-proxy会使用PAC代理。

+

不同的代理方式,对于配置文件更新的处理也不一样。

+

如果使用普通代理,配置文件更新之后,不用重启浏览器,直接更刷新浏览器即可生效。

+

但是如果使用PAC代理,如果新增了域名,目前.pac文件并不会立刻更新,需要手动刷新浏览器的代理文件。可以访问chrome://net-internals/#proxy然后点击Re-apply settings

+

代理规则合并

所有配置文件中的规则最终都会合并到一个大的规则树中。也就是说配置了代理之后,在处理请求的时候,所有配置文件中的规则都是平等的。不同域名中的规则互不影响。相同域名中的规则合并,如果有重复的路由,后加载的配置文件中的路由覆盖之前加载的配置文件内容

+

比如,有两个配置文件workspace/blog/rewriteworkspace/docs/rewrite,文件内容如下:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
# workspace/blog/rewrite

domain hiproxy.org {
location /blog/ {
proxy_pass http://127.0.0.1:8000/;
}
}

domain blog.hiproxy.org {
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
+
1
2
3
4
5
6
7
# workspace/docs/rewrite

domain hiproxy.org {
location /docs/ {
proxy_pass http://127.0.0.1:9000/;
}
}
+

合并之后的规则为:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 合并之后的规则

domain hiproxy.org {
location /blog/ {
proxy_pass http://127.0.0.1:8000/;
}
}

domain hiproxy.org {
location /docs/ {
proxy_pass http://127.0.0.1:9000/;
}
}

domain blog.hiproxy.org {
location / {
proxy_pass http://127.0.0.1:8000/;
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/configuration/rewrite.html b/zh-cn/configuration/rewrite.html new file mode 100644 index 0000000..b243239 --- /dev/null +++ b/zh-cn/configuration/rewrite.html @@ -0,0 +1,211 @@ + + + + + Rewrite | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/configuration/ssl_certificate.html b/zh-cn/configuration/ssl_certificate.html new file mode 100644 index 0000000..fdd00d7 --- /dev/null +++ b/zh-cn/configuration/ssl_certificate.html @@ -0,0 +1,291 @@ + + + + + 获取/安装hiproxy根证书 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

获取/安装hiproxy根证书

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

hiporxy会自己生成一个根证书,扮演CA的角色(Hiproxy Custom CA)。hiproxy在代理https请求的时候,会自动生成证书并使用hiproxy的根证书签名。

+

由于系统是不信任hiproxy根证书的,所以需要我们自己手动安装信任hiproxy的根证书。

+

下载证书

启动hiproxy服务之后(假设端口号是5525),可以访问http://127.0.0.1:5525/ssl-certificate获取Hiproxy Custom CA的根证书。

+

这个地址,可以在http://127.0.0.1:5525/中找到,如下图:

+

+

安装证书

下面将分别介绍OSX、iOS、Windows和Android中如何安装根证书。

+

OSX系统

    +
  1. 下载完成根证书之后,双击Hiproxy_Custom_CA_Certificate.pem导入证书到钥匙串。

    +
  2. +
  3. 在弹出的对话框中输入用户密码。

    +
  4. +
  5. 此时证书是不受信任状态,双击刚才导入的证书。

    +
  6. +
+

+
    +
  1. 信任 > 使用此证书时下面选择始终信任
  2. +
+

+
    +
  1. 关闭对话框,此时证书已经是被信任状态。
  2. +
+

+

iOS系统

    +
  1. 下载完成根证书之后发送到手机并打开。

    +
  2. +
  3. 点击右上角的安装

    +
  4. +
+

+
    +
  1. 再次点击右上角的安装
  2. +
+

+
    +
  1. 完成安装,点击右上角完成退出。
  2. +
+

+
    +
  1. 如果iOS系统版本 >= 10.3,需要在设置 > 通用 > 关于本机中点击证书信任设置
  2. +
+

+
    +
  1. 打开开关Hiproxy Custom CA
  2. +
+

+

Windows

    +
  1. 下载完成根证书之后,双击Hiproxy_Custom_CA_Certificate.crt安装证书。

    +
  2. +
  3. 在弹出的对话框中点击安装证书

    +
  4. +
+

+
    +
  1. 点击下一步
  2. +
+

+
    +
  1. 选择将所有的证书放入下列存储(P),点击浏览(R),然后选择受信任的根证书颁发机构,点击确定
  2. +
+

+
    +
  1. 点击下一步完成。根据页面提示完成根证书安装。。
  2. +
+

+

Android

    +
  1. 下载完成根证书之后发送到手机。

    +
  2. +
  3. 设置 > 安全中点击从SD卡安装

    +
  4. +
+

+
    +
  1. 输入解锁密码,然后输入证书名称,比如HiproxyCustomCA,点击确定
  2. +
+

+
    +
  1. 设置 > 安全 > 受信任的证书 > 用户中,如果能看到hiproxy的根证书,表示安装成功。
  2. +
+

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/developers/cli_command.html b/zh-cn/developers/cli_command.html new file mode 100644 index 0000000..da7dcd6 --- /dev/null +++ b/zh-cn/developers/cli_command.html @@ -0,0 +1,222 @@ + + + + + CLI命令配置 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

CLI命令配置

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

简介

hiproxy的CLI提供了start/stop/state/open等命令,如果这些命令不能满足你的需求,也可以为hiproxy添加新的命令。

+

新增的命令需要配置的内容为:命令名称描述使用方法处理函数命令选项参数。对应的字段为:

+
    +
  • 命令名称(command)<String>,比如:'hello'
  • +
  • 描述信息(describe)<String>,简单介绍命令的作用以及其他的信息,比如:'A test command that say hello to you.'
  • +
  • 使用方法(usage)<String>,命令的使用方法提示信息,比如:'hello [--name <name>] [-xodD]'
  • +
  • 处理函数(fn)<Function>,执行命令时,调用的函数。函数调用时this值为命令行参数解析后的对象。
  • +
  • 命令选项(option)<Object>,命令对应的选项,key:value形式。可以参考https://github.com/hemsl/hemsl
  • +
+

示例

一个完整的命令示例如下:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{
command: 'hello',
describe: 'A test command that say hello to you.',
usage: 'hello [--name <name>] [-xodD]',
fn: function () {
var cliArgs = this;
if (cliArgs.name ) {
console.log('your name is', cliArgs.name.green);
}

if (cliArgs.age ) {
console.log('your are', cliArgs.age.green, 'years old');
}
},
options: {
'name <name>': {
alias: 'n',
describe: 'your name'
},
'age': {
alias: 'a',
describe: 'your age'
}
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/developers/directive.html b/zh-cn/developers/directive.html new file mode 100644 index 0000000..7ba5063 --- /dev/null +++ b/zh-cn/developers/directive.html @@ -0,0 +1,230 @@ + + + + + 指令配置 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

指令配置

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

简介

rewrite指令可以配置的内容为:指令名称作用域处理函数。对应的字段为:

+
    +
  • 指令名称(name)<String>,比如:'add'
  • +
  • 作用域(scope)<Array>,指令对应的作用域,只有在这里指定的作用域里面才会执行。可选择的作用域为:globaldomainlocationrequestresponse
  • +
  • 处理函数(fn)<Function>,执行指令时,调用的函数,详细信息请查看处理函数
  • +
+

示例

一个完整的指令示例如下:

+
1
2
3
4
5
6
7
8
9
10
{
name: 'add',
scope: ['global', 'domain', 'location'],
fn: function (key, a, b) {
var props = this.props;
var value = Number(a) + Number(b);

this.props[key] = value;
}
}
+

+

处理函数

处理函数会在hiproxy执行指令的时候被调用,传入rewrite配置文件中这个指令对应的参数,并设置this

+

参数

处理函数会被调用是,会传入rewrite配置文件中这个指令对应的参数,例如配置了指令proxy_set_header Host hiproxy.org,那么在执行处理函数时,传入的参数为:('Host', 'hiproxy.org')

+

this

不同作用域中的指令执行时,this值也不同,下面列举了所有作用域指令对应的this值:

+
    +
  • global: 整个rewrite对象-{props: <Object>, domains: <Array>, commands: <Array>}}
  • +
  • domain: domain对象-{domain: <String>, props: <Object>, location: <Array>, commands: <Array>}}
  • +
  • location: location对象-{props: <Object>, location: <String>, commands: <Array>}}
  • +
  • request: {request: <http.IncomingMessage>}
  • +
  • response: {response: <http.ServerResponse>}
  • +
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/developers/index.html b/zh-cn/developers/index.html new file mode 100644 index 0000000..933c694 --- /dev/null +++ b/zh-cn/developers/index.html @@ -0,0 +1,211 @@ + + + + + hiproxy开发者指南 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

hiproxy开发者指南

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/developers/plugin.html b/zh-cn/developers/plugin.html new file mode 100644 index 0000000..0382c13 --- /dev/null +++ b/zh-cn/developers/plugin.html @@ -0,0 +1,235 @@ + + + + + 插件开发指南 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

插件开发指南

+ +
+
+

hiproxy提供了一套插件开发机制,这个机制很简单:插件开发完成后,将插件安装到全局,hiproxy启动时会自动查找安装的所有插件。

+

开发者开发新插件时,可以参考hiproxy-plugin-example: https://github.com/hiproxy/hiproxy-plugin-example。这是一个完整的插件示例,你可以基于这个示例修改。

+

插件就是一个普通的npm模块,不需要将hiproxy作为依赖安装到插件中。

+


+

插件结构

hiproxy插件必须满足三个条件:

+
    +
  1. 插件必须作为一个独立的npm模块,这个模块需要导出一个对象,这个对象可以指定三个属性
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    module.exports = {
    // CLI commands
    commands: commands,

    // Rewrite config redirectives
    directives: directives,

    // HTTP server routes
    routes: routes
    };
    +
  2. +
+
    +
  • commands: <Array>,用来扩展hiproxyCLI命令,数组中每个对象作为一个命令配置,具体配置见命令配置

    +
  • +
  • directives: <Array>,用来扩展hiproxyrewrite指令,数组中每个对象作为一个指令配置,具体配置见指令配置

    +
  • +
  • routes: <Array>,用来扩展hiproxy页面路由,数组中每个对象作为一个路由配置,具体配置见路由配置

    +
  • +
+
    +
  1. 插件模块必须安装到全局

    +
  2. +
  3. 插件名称必须以hiproxy-plugin-开头

    +
  4. +
+

代码示例

https://github.com/hiproxy/hiproxy-plugin-example/blob/master/index.js#L14-L23

+

插件发布

插件开发、测试完成之后,可以将其发布到npm。

+

发布的过程和方法,跟其他npm模块的发布一样,因为hiproxy的插件,就是一个遵循了特定规则的普通npm模块

+

温馨提示

由于hiproxy只会从npm root -g所在的目录去查找名称以hiproxy-plugin-开头的插件,所以在本地开发时,hiproxy加载不到新的插件。

+

可以使用npm link,创建一个符号链接,这样就能一边开发一边调试开发中的插件。详情请参考npm文档:npm link

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/developers/route.html b/zh-cn/developers/route.html new file mode 100644 index 0000000..b59572c --- /dev/null +++ b/zh-cn/developers/route.html @@ -0,0 +1,226 @@ + + + + + 页面路由配置 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

页面路由配置

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

简介

hiproxy启动服务之后,可以访问http://127.0.0.1:<port>/页面查看服务的一些基本信息。

+

除了上面的页面之外,hiproxy还提供了增加新页面的功能。比如插件hiproxy-plugin-dashboard,为hiproxy增加了一个在线查看服务信息以及修改配置文件的页面,地址为:http://127.0.0.1:<port>/dashboard/

+

配置内容

页面路由可以配置的内容为:路由规则渲染函数。对应的字段为:

+
    +
  • 路由规则(route):<String>,页面的地址模式,比如:'/dashboard(/:page)',细节可以查看https://www.npmjs.com/package/url-pattern
  • +
  • 渲染函数(render):<Function>,渲染页面,接收三个参数:(route, request, response)
  • +
+

render方法

当用户访问对应的页面时,render()方法会被调用,传入三个参数(route, request, response)

+
    +
  • route: <Object>,url模式匹配后的对象,比如配置了/test(/:pageName)之后,访问/test/homeroute的值为:{pageName: 'home'}
  • +
  • request: <http.IncomingMessage>,http请求对象。
  • +
  • response: <http.ServerResponse>,http响应对象。
  • +
+

示例

一个完整的页面扩展示例如下:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
route: '/test(/:pageName)',
render: function (route, request, response) {
   // 这里面可以使用全局变量`hiproxyServer`来获取hiproxy服务实例
   response.writeHead(200, {
'Content-Type': 'text/html',
'Powder-By': 'hiproxy-plugin-example'
});

var serverInfo = {
route: route,
pageID: route.pageName,
time: new Date(),
serverState: {
http_port: global.hiproxyServer.httpPort,
https_port: global.hiproxyServer.httpsPort,
cliArgs: global.args,
process_id: process.pid
}
};

response.end('<pre>' + JSON.stringify(serverInfo, null, 4) + '</pre>');
}
}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/faqs/index.html b/zh-cn/faqs/index.html new file mode 100644 index 0000000..a0b5f6b --- /dev/null +++ b/zh-cn/faqs/index.html @@ -0,0 +1,238 @@ + + + + + 常见问题 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

常见问题

+ +
+
+

hiproxy的核心目的/功能是什么?

hiproxy的核心功能是代理请求,主要是为了解决前端开发工程师在本地开发过程中遇到的:

+
    +
  • hosts修改后由于DNS缓存不能立刻生效
  • +
  • 需要使用Nginx来做反向代理
  • +
  • 自签名HTTPS证书不受信任
  • +
  • 每个人都在本地维护环境配置文件(hosts/Nginx配置)
  • +
  • +
+


+

hiproxy跟Charles/Fiddler有什么区别?

hiproxy跟Charles/Fiddler都有抓包、请求代理的功能,很多核心的功能基本类似。只不过hiproxy是一个命令行的工具,使用配置文件来配置。

+

此外,hiproxy现在没有查看网络请求的具体内容的界面,将来会通过插件开发,敬请期待。

+


+

hiproxy的hosts跟系统hosts有什么关系?

hiproxy的hosts跟系统hosts文件本身没有任何关系。

+

hiproxy的hosts文件一般存放在项目中,或者其他目录(根据用户情况自己决定放到哪里)。hiproxy代理服务启动的时候,会查找并解析这些hosts文件,不会去查找解析系统hosts

+


+

hiproxy的rewrite配置文件完全兼容Nginx配置吗?

不兼容,hiproxy的rewrite规则配置文件跟Nginx的配置文件本身没有任何关系。

+

从语法上看,hiproxy的rewrite配置文件借鉴了Nginx配置的语法。核心的语法跟Nginx的语法一致,但是也有些语法是hiproxy特有的,并不完全跟Nginx语法一致,比如:

+
1
2
3
4
5
6
7
# base rule
http://hiproxy.org/api/login.do => http://127.0.0.1:9999/api/login.json;

# domain
hiproxy.org => {
# ...
}
+

此外,也有部分指令采用Nginx的指令名称且功能基本类似,比如proxy_passsetssl_certificatessl_certificate_key等。但是也不保证所有的功能细节跟Nginx的指令保持一致。详细的指令功能说明请参考指令

+


+

hiproxy支持多个项目中的不同配置文件使用相同的域名吗?

支持。

+

可以在不同的项目的不同配置文件中,给相同的域名配置代理规则。hiproxy会自动合并相同域名的规则,如果路由配置有冲突,后加载的配置文件的规则会覆盖前面的规则。

+


+

hiproxy怎么处理多个配置文件中的规则冲突?

详细的配置规则处理文档正在编写。

+


+

hiproxy根证书怎么获取/导入?

可以查看文档获取/导入SSL证书

+


+

hiproxy中如何使用自己的SSL证书?

默认情况下,在代理https请求的时候,hiproxy会自动生成证书,并使用hiproxy自定义的CA证书签名。用户只需要导入hiproxy的根证书。

+

如果用户需要使用自定义的证书,可以使用hiproxy提供的指令来配置:

+
1
2
ssl_certificate     ./hiproxy.org.crt;
ssl_certificate_key ./hiproxy.org.key;
+


+

+
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/get_started/applied_to_existing_projects.html b/zh-cn/get_started/applied_to_existing_projects.html new file mode 100644 index 0000000..d7f6b2a --- /dev/null +++ b/zh-cn/get_started/applied_to_existing_projects.html @@ -0,0 +1,245 @@ + + + + + 运用到现有项目中 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

运用到现有项目中

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

1、全局安装hiproxy

如果你还没有安装hiproxy,请查看如何安装hiproxy。

+

我们只需要把hiproxy安装到全局就可以了,不需要将hiproxy作为一个依赖安装到每个项目中

+

2、添加配置文件

hiproxy的两个理念:

+
    +
  • 所有的项目都放到一个工作空间(workspace)下面;
  • +
  • 将配置文件(hosts/rewrite配置)放到对应的项目中,提交带代码仓库里面进行版本控制,与团队中其他成员共享。
  • +
+

所以,我们需要把配置文件存放到对应的项目中。针对不同的项目,可以添加不同的配置文件。hiproxy在启动的时候,会自动从工作目录下面查找配置文件。

+

推荐的工作空间目录结构如下:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
workspace
├── app-1 # 项目1
│   ├── hosts # hosts文件
│   ├── rewrite # rewrite文件
│   └── src # 项目代码
│   └── ... # 其他文件

├── app-2 # 项目2
│   ├── hosts # hosts文件
│   ├── rewrite # rewrite文件
│   └── src # 项目代码
│   └── ... # 其他文件

└── app-3 # 项目3
├── hosts # hosts文件
├── rewrite # rewrite文件
└── src # 项目代码
   └── ... # 其他文件
+

当然,如果你实在是不希望这样去做,想把所有的配置都放到项目之外,你也可以通过启动时添加选项(option)来制定配置文件路径:

+
1
2
-c, --hosts-file <files>   hosts files, format: <file1>[,<file2>[,...]]
-r, --rewrite-file <files> rewrite config files, format: <file1>[,<file2>[,...]]
+
+

提示

+
    +
  • -c, --hosts-file-r, --rewrite-file支持简化版的模式匹配;比如:./*/*.conf
  • +
  • 支持的语法:*, ?, [abc], [a-z], [^a-z], [!a-z]
  • +
  • 不支持的语法:**
  • +
+
+

2.1、添加hosts

hosts跟系统hosts类似,只不过这个hosts是放到项目中的,如果我们在项目根目录下面创建了hosts文件并且文件名称为hosts,hiproxy能自动发现并解析它。

+

如果文件名称不是hosts,则需要我们通过-c, --hosts-file来指定。

+

hosts配置详情,请查看hosts配置

+

2.2、添加rewrite

rewrite跟hosts一样,也是放到项目中的,如果我们在项目根目录下面创建了名称为rewrite的文件,hiproxy也能自动发现并解析它。

+

如果文件名称不是rewrite,则需要我们通过-r, --rewrite-file来指定。

+

rewrite配置详情,请查看rewrite配置

+

3、提交git

hiproxy希望大家能把上面添加的hosts/rewrite配置文件提交到git中,这样团队中的成员更新代码之后,就能使用这些配置,免去了互相拷贝配置文件的苦恼。

+

4、启动服务

hiproxy的理念是基于工作空间。我们需要在工作空间下启动hiproxy代理服务。假设我们所有的项目都存放在~/workspace/,那么这么目录就是我们的工作空间。

+

当我们进入到这个目录,然后启动hiproxy代理服务,那么hiproxy将查找这个目录下面所有项目的配置文件。

+

如果你不希望进入工作空间再启动代理服务,也可以在任意目录启动hiproxy并使用选项-w, --workspace <workspace>,比如:

+
1
2
# 进入到任意目录
hiproxy start -w ~/workspace/
+

提示:在启动hiproxy代理服务的时候,建议使用-o, --open [browser-name]来打开一个浏览器窗口并自动配置好代理。这样就不需要我们自己手动去配置代理。

+

5、开发调试

启动hiproxy代理服务之后,打开的浏览器窗口里面的所有请求,如果配置了代理规则,都会交给hirpoxy去处理。

+

不需要配置系统hosts。

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/get_started/cli_options.html b/zh-cn/get_started/cli_options.html new file mode 100644 index 0000000..d7279c8 --- /dev/null +++ b/zh-cn/get_started/cli_options.html @@ -0,0 +1,224 @@ + + + + + CLI 选项 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

CLI 选项

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

Command Line Commands and Options

Global Commands

The global hiproxy command without any options will display a welcome message like this:

+
1
2
3
4
5
6
7
> hiproxy
_ _
| | (_)
| |__ _ welcome to use hiproxy
| '_ \| | current version is 1.1.2
| | | | | You can try `hiproxy --help` for more info
|_| |_|_|
+

If you specify the option --help or -h, you will see the complete help information.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
> hiproxy --help

Usage:

hiproxy [command] [option]

Commands:

start Start a local proxy server
stop Stop the local proxy server (Only works in daemon mode)
restart Restart the local proxy service (Only works in daemon mode)
state Show all the servers state (Only works in daemon mode)
open Open browser and set proxy
hello A test command that say hello to you.

Options:

-v, --version Display version information
-h, --help Display help information
--log-dir <dir> The log directory when run in background, default: user home directory
--log-time Show time info before every log message
--log-level The log levels, format: <level1>[,<lavel2[,...]] available parameters : log info warn error debug detail
--grep <content> Filter the log data
+

start

This command will start a local proxy service on the specified port. You can specify whether the service is running in the background, if running in the background, all the log of the service will be rediret to the log files.

+

The log file is located in the user’s home directory by default. Of course, you can specify the log file’s path via the option --log-dir <dir>.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
> hiproxy start --help

USAGE:

start [--port <port>] [-xodD]

DESCRIBE:

Start a local proxy server

OPTIONS:

-h, --help show help info
-D, --daemon Run hiproxy in background
-c, --hosts-file <files> hosts files, format: <file1>[,<file2>[,...]]
-s, --https Enable HTTPS proxy
-m, --middle-man-port <port> The Man-In-The-MiddleHTTPS proxy port, default: 10010
-o, --open [browser] Open a browser window and use hiproxy proxy
--pac-proxy Use Proxy auto-configuration (PAC)
-p, --port <port> HTTP proxy port, default: 5525
-r, --rewrite-file <files> rewrite config files, format: <file1>[,<file2>[,...]]
--sys-proxy <path> Your own proxy server path, format: <ip>[:port], only works when use PAC
-w, --workspace <dir> The workspace
+

stop

If the proxy service is running in the background, hiproxy provides a stop command to stop the service

+
1
> hiproxy stop
+

open

The open command can open a browser window and automatically set up the browser’s proxy info based on the currently started proxy service.

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
> hiproxy open --help

USAGE:

open [options]

DESCRIBE:

Open browser and set proxy

OPTIONS:

-h, --help show help info
-b, --browser <browser> Browser name, default: chrome. Valid alues: chrome,firefox,opera
--pac-proxy Use Proxy auto-configuration (PAC)
+

state

This command will display the basic status information of the currently started proxy service.

+

restart

This command will restart the proxy service.

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/get_started/index.html b/zh-cn/get_started/index.html new file mode 100644 index 0000000..49f08c2 --- /dev/null +++ b/zh-cn/get_started/index.html @@ -0,0 +1,277 @@ + + + + + 简介 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

简介

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

hiproxy是一个基于Node.js开发的轻量、可扩展的网络代理工具,主要目的是为了解决多个开发者在开发过程中遇到的hosts管理和请求代理的问题。使得在开发时,不再需要修改系统hosts和启动一个Nginx服务。

+

hiproxy支持hosts配置文件,同时也扩展了hosts的语法,支持端口号。此外,hiproxy还支跟Nginx配置文件相似语法的配置文件。

+

为什么要开发hiproxy

在前端开发中,如果我们通常会遇到下面的一些问题:

+
    +
  1. 调试线上页面问题,要在本地进行开发,需要能运行后端的项目(Node.js或者Java等项目),前端工程师在本地搭建一套后端环境,可能代价比较大
  2. +
  3. 如果有多个前端工程,采用一个域名部分工程 需要请求 线上 资源,部分 工程请求 本地
  4. +
  5. 为解决跨域等问题,本地开发时需要 修改Response Header
  6. +
  7. 本地开发https站点时,证书不受信任
  8. +
  9. 系统 hosts修改 后,不会立即生效
  10. +
+

我们可以使用Nginx来解决上面的问题。Nginx很优秀,也是我们前端开发工程师的一个非常好的朋友。Nginx的配置文件风格,非常直观,编写配置效率很高。

+

但是,使用Nginx的时候,我们同时需要使用hosts,把相关请求发送到本地的Nginx服务。

+

此外,大部分情况下,Nginx的配置文件并不会被提交到代码仓库,所以团队中其他开发者之间会互相拷贝配置文件,这样效率比较低,而且一个人修改了配置文件,其他人的配置不会随之更新。对于多个域名的配置,也都是放到一个统一的目录,然后在主配置里面include,这样也不太方便。

+

hosts反向代理https缓存 这些琐碎的事情,能不能统一解决?

+

于是有了hiproxy。

+

特色

    +
  • 支持Nginx风格的配置文件格式,配置简单直观
  • +
  • 支持hosts以及扩展(支持端口号)
  • +
  • 支持插件扩展rewrite指令、CLI命令和页面
  • +
  • 支持HTTPS证书自动生成
  • +
  • 支持代理自动配置(Proxy auto-config)
  • +
  • 支持后台启动,日志输出到文件
  • +
  • 支持配置文件自动查找
  • +
  • 支持打开浏览器窗口并自动配置代理
  • +
  • 提供Node.js API
  • +
  • +
+

理念

我们经过对很多现有开发模式的反思、总结现在遇到的一些问题,基于以下两个理念开发出了hiproxy:

+
    +
  • 工作空间:hiproxy工作在工作空间(workspace)中,工作空间中所有项目的配置文件都会被hiproxy解析。工作空间可以通过-w, --workspace <workspace>来指定,也可以直接进入到工作空间启动代理服务
  • +
  • 配置文件共享:配置文件,提交到代码仓库,团队成员共享配置。之前hosts和Nginx配置一般都是不提交到代码仓库,团队成员各自本地维护,成本大并且效率比较低。
  • +
+

基本原理

hiproxy的核心功能是请求代理,在代理请求的同时,处理了一些开发中的细节问题,比如https证书自动生成、自动配置浏览器代理等。

+

下面讲介绍hiproxy核心功能的基本原理。

+

请求代理

hiproxy充分利用了中间人攻击模式,作为中间人在客户端和服务器端转发数据,来实现HTTP以及HTTPS请求的代理。

+

HTTP请求代理

对于HTTP请求,如果浏览器配置了代理,浏览器会发送GET/POST等请求给hiproxy代理。hiproxy收到请求之后,根据用户的hostsrewrite规则配置,对请求的信息做一定的修改,然后去相应的服务器请求资源并返回给客户端。

+

HTTPS请求代理

对于HTTPS请求,配置代理之后,浏览器会发送CONNECT请求到hiproxy服务,hiproxy会新建一个到最终目标服务器的TCP连接(也就是新建了一个隧道)然后在客户端和服务端之间转发数据。

+

但是这只是能简单代理请求,hiproxy没办法获取到请求的信息,比如参数和Cookie,更没有办法修改响应的数据。如果不需要对请求、响应的信息做对应的修改,这就能满足我们的需求。

+

如果我们需要实现跟HTTP请求一样的功能:根据请求的信息,对请求和响应做一些修改,需要怎么做呢?

+

好在我们可以充分利用中间人攻击这种模式。因为最终的目标服务器能获取到请求的信息,我们可以在hiproxy和最终服务器之间再启动一个中间人服务(这里简称为M),当hiproxy收到CONNECT请求之后,新建一个到M的连接,当M收到请求之后,跟HTTP请求代理一样,对请求信息做一些修改,然后去目标服务器请求资源并返回给客户端。

+

HTTPS证书生成

在SSL/TLS握手过程中,客户端发送的第一个消息(Client Hello)中,会使用SNI(Server Name Indication +)扩展,将请求的域名发送给服务器。虽然只发送了域名信息,并没有发送其他的请求路径、参数和cookie等信息,但是对于生成证书来说,有域名已经足够。

+

当hiproxy获取到请求的域名时:

+
    +
  • 如果用户给对应的域名配置了证书,将用户配置的证书发送给客户端。
  • +
  • 否则,生成新的域名证书返回给客户端。
  • +
+

浏览器窗口

首先,找到系统中浏览器对应的路径。比如在OSX上,查找<browser-name>.app,然后启动这个app,并传入参数来配置代理服务器地址。

+
1
<path-to-chrome-app>.app [options] [url]
+

在windows上,会去注册表中查找对应浏览器的exe文件路径。然后运行并传递参数。

+
1
<path-to-chrome-app>.exe [options] [url]
+

对于Chrome/Opera浏览器来说,我们需要传递两个方面的参数:

+
    +
  • 代理服务的地址--proxy-pac-url(PAC代理文件路径)和--proxy-server(普通代理地址)二选一,这两种代理hiproxy都支持。

    +
  • +
  • 用户数据存放的目录--user-data-dir当传递这个参数,并且这个目录不是浏览器默认存放用户数据的目录,则会新建一个新的浏览器实例,这个示例独立于其他的浏览器窗口,互不影响(这个实例配置了代理,其他浏览器实例的请求不会通过这里配置的代理)。

    +
  • +
+

配置文件

hiproxy可以使用hosts来做简单的请求代理,对于复杂的配置使用跟Nginx语法类似的rewrite规则配置。

+

hosts

跟系统hosts语法一致,此外也支持端口号。hosts只能配置域名对应的ip和端口号,不支持详细的路由配置以及对请求响应做修改。更多详细信息请查看hosts

+

hosts配置示例

1
2
3
4
5
# comment
127.0.0.1 example.com

# ip + port
127.0.0.1:8800 blog.example.com life.example.com
+

rewrite

rewrite规则配置文件,可以使用更复杂的配置、满足复杂的使用场景。可以对路由进行详细的配置以及对请求响应做修改。rewrite规则配置的语法,跟Nginx语法非常类似。更多详细信息请查看rewrite

+

rewrite配置示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 全局变量
set $port 8899;
set $ip 127.0.0.1;
set $online 210.0.0.0;

# 域名配置
domain example.com {
location / {
proxy_pass http://$online/;
}

location /blog/ {
proxy_pass http://$ip:$port/blog/;
proxy_set_header from 'hiproxy';
set_header proxy 'hiproxy';
}
}
+

插件机制

hiproxy启动的时候,会自动从npm全局模块所在目录(npm root -g)查找以hiproxy-plugin-开头的模块,找到这些模块之后自动解析插件内容。

+

因此,我们只需要独立全局安装需要的插件,不用去升级hiproxy,hiproxy插件的开发也是独立的,插件项目本身不依赖hiproxy。

+

详细的插件相关文档请查看hiproxy插件指南

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/get_started/installation.html b/zh-cn/get_started/installation.html new file mode 100644 index 0000000..a1efbbf --- /dev/null +++ b/zh-cn/get_started/installation.html @@ -0,0 +1,224 @@ + + + + + 安装 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

安装

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

安装hiproxy

通过npm安装

hiproxy已经发布到npm,您可以通过npm来安装: +

1
npm install -g hiproxy

+

如果您希望使用最新的测试版本功能(可能不稳定),可以选择安装hiproxy的beta版本: +

1
npm install -g hiproxy@beta

+

此外,您也可以直接使用github源码安装: +

1
npm install -g hiproxy/hiproxy

+

提示:如果您还没有安装Node.js,可以到Node.js官网下载安装。

+

通过yarn安装

hiproxy也支持通过yarn来安装: +

1
yarn global add hiproxy

+

安装插件

hiproxy也支持插件扩展。插件可以独立于hiproxy安装,直接安装到全局即可。

+

比如我们要安装插件hiporxy-plugin-dashboard,可以执行下面的命令:

+
1
npm install hiproxy-plugin-dashboard -g
+

安装之后,hiproxy下次启动的时候,会自动加载安装好的插件。

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/get_started/run_example.html b/zh-cn/get_started/run_example.html new file mode 100644 index 0000000..bccfb4e --- /dev/null +++ b/zh-cn/get_started/run_example.html @@ -0,0 +1,238 @@ + + + + + 运行示例项目 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

运行示例项目

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

项目简介

我们准备了一个示例工程,里面有一个工作空间(workspace),工作空间中包含三个简单的项目。三个项目分别使用端口800080018002

+

同时,我们也提供了一个脚本server.js,来启动三个服务,可以使用npm start或者node start

+

这个项目的目录结构如下:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
.
├── LICENSE
├── README.md
├── package.json
├── start.js # 启动服务
└── workspace # 工作空间
├── blog-app # blog应用示例
│   ├── app.js # express app
│   ├── hosts # hosts文件
│   ├── public # 静态资源
│   └── rewrite # rewrite配置文件
├── main-app # 主应用示例
│   ├── app.js # express app
│   ├── hosts # hosts文件
│   └── public # 静态资源
└── news-app # 新闻应用示例
├── app.js # express app
└── hosts # hosts文件
+

workspace目录下,有三个应用,每个应用都有一个hosts文件:

+
1
2
# main-app hosts
127.0.0.1:8000 www.example.com
+
1
2
# blog-app hosts
127.0.0.1:8001 blog.example.com
+
1
2
# news-app hosts
127.0.0.1:8002 news.example.com
+

在blog-app中,还有一个rewrite文件,内容如下:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# rewrite rules
domain blog.example.io {
# rewrite / to 8001;
location / {
proxy_pass http://127.0.0.1:8001/;
}

# static files
location /static/ {
alias ./public/;

set_header server hiproxy;
set_cookie server hiproxy;
}
}
+

+

运行步骤

第一步:clone代码

示例项目的代码托管在github上,首先使用Git把代码clone到本地:

+
1
git clone https://github.com/hiproxy/hiproxy-example.git
+

第二步:安装依赖

然后进入项目根目录(hiproxy-example/),安装需要的第三方依赖:

+
1
2
cd hiproxy-example
npm install
+

第三步:启动服务

克隆完源码并安装好依赖后,就可以启动示例项目提供的服务了。在hiproxy-example/下执行:

+
1
npm start
+

第四步:启动hiproxy

上面的准备工作完成之后,我们就可以启动hiproxy来体验他的功能了,在hiproxy-example/下执行:

+
1
hiproxy start --https --open --workspace ./workspace
+

第五步:访问测试页面

在执行上一步的命令后,hiproxy会贴心的打开一个浏览器窗口并配置好代理。在这个浏览器中访问下面任意一个网址即可查看效果:

+ + +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/images/android_install_cert_1.png b/zh-cn/images/android_install_cert_1.png new file mode 100644 index 0000000..0bc9979 Binary files /dev/null and b/zh-cn/images/android_install_cert_1.png differ diff --git a/zh-cn/images/android_install_cert_2.png b/zh-cn/images/android_install_cert_2.png new file mode 100644 index 0000000..d80f0f9 Binary files /dev/null and b/zh-cn/images/android_install_cert_2.png differ diff --git a/zh-cn/images/android_install_cert_3.png b/zh-cn/images/android_install_cert_3.png new file mode 100644 index 0000000..025aed5 Binary files /dev/null and b/zh-cn/images/android_install_cert_3.png differ diff --git a/zh-cn/images/hiproxy_start_page.png b/zh-cn/images/hiproxy_start_page.png new file mode 100644 index 0000000..8431c28 Binary files /dev/null and b/zh-cn/images/hiproxy_start_page.png differ diff --git a/zh-cn/images/import_root_cert.png b/zh-cn/images/import_root_cert.png new file mode 100644 index 0000000..c6e60ab Binary files /dev/null and b/zh-cn/images/import_root_cert.png differ diff --git a/zh-cn/images/ios_install_cert_1.jpg b/zh-cn/images/ios_install_cert_1.jpg new file mode 100644 index 0000000..53361f8 Binary files /dev/null and b/zh-cn/images/ios_install_cert_1.jpg differ diff --git a/zh-cn/images/ios_install_cert_2.jpg b/zh-cn/images/ios_install_cert_2.jpg new file mode 100644 index 0000000..5408bbf Binary files /dev/null and b/zh-cn/images/ios_install_cert_2.jpg differ diff --git a/zh-cn/images/ios_install_cert_3.jpg b/zh-cn/images/ios_install_cert_3.jpg new file mode 100644 index 0000000..903e494 Binary files /dev/null and b/zh-cn/images/ios_install_cert_3.jpg differ diff --git a/zh-cn/images/ios_install_cert_4.jpg b/zh-cn/images/ios_install_cert_4.jpg new file mode 100644 index 0000000..a5b5452 Binary files /dev/null and b/zh-cn/images/ios_install_cert_4.jpg differ diff --git a/zh-cn/images/ios_install_cert_5.jpg b/zh-cn/images/ios_install_cert_5.jpg new file mode 100644 index 0000000..fa4f298 Binary files /dev/null and b/zh-cn/images/ios_install_cert_5.jpg differ diff --git a/zh-cn/images/root_cert_trusted.png b/zh-cn/images/root_cert_trusted.png new file mode 100644 index 0000000..f21add5 Binary files /dev/null and b/zh-cn/images/root_cert_trusted.png differ diff --git a/zh-cn/images/trust_root_cert.png b/zh-cn/images/trust_root_cert.png new file mode 100644 index 0000000..c610460 Binary files /dev/null and b/zh-cn/images/trust_root_cert.png differ diff --git a/zh-cn/images/windows_install_cert.png b/zh-cn/images/windows_install_cert.png new file mode 100644 index 0000000..03baf85 Binary files /dev/null and b/zh-cn/images/windows_install_cert.png differ diff --git a/zh-cn/images/windows_install_finish.png b/zh-cn/images/windows_install_finish.png new file mode 100644 index 0000000..3bcd6cb Binary files /dev/null and b/zh-cn/images/windows_install_finish.png differ diff --git a/zh-cn/images/windows_step_1.png b/zh-cn/images/windows_step_1.png new file mode 100644 index 0000000..e12f17a Binary files /dev/null and b/zh-cn/images/windows_step_1.png differ diff --git a/zh-cn/images/windows_step_2.png b/zh-cn/images/windows_step_2.png new file mode 100644 index 0000000..6bafc27 Binary files /dev/null and b/zh-cn/images/windows_step_2.png differ diff --git a/zh-cn/index.html b/zh-cn/index.html new file mode 100644 index 0000000..14caf38 --- /dev/null +++ b/zh-cn/index.html @@ -0,0 +1,182 @@ + + + + + hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + +
+
+
+
  • 轻量可扩展

    hiproxy是一个轻量级的代理工具,依赖的库比较少,安装快速,开发者可以对hiproxy进行扩展,支持扩展命令、指令和页面。

  • 复用现有开发习惯

    采用hosts和Nginx风格的配置,最大程度复用之前的开发、配置习惯。学习成本低,使用起来更加轻松。

  • HTTPS证书自动生成与管理

    hiproxy可以扮演CA角色,生成根证书。并且能自动根据每次请求的域名信息,生成相对应的域名证书。

  • 跟浏览器高度融合

    hiproxy在启动服务的时候,可以贴心地打开一个新的浏览器窗口并自动配置好代理,省去了用户自己设置代理的步骤。

+
    +
  • npm install hiproxy -g
  • +
  • hiproxy init
  • +
  • hiproxy start --open
  • +
+ +
+
+
+ + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/rewrite/built_in_variable.html b/zh-cn/rewrite/built_in_variable.html new file mode 100644 index 0000000..eb9db61 --- /dev/null +++ b/zh-cn/rewrite/built_in_variable.html @@ -0,0 +1,235 @@ + + + + + rewrite内置变量 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

rewrite内置变量

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

hiproxy的rewrite规则配置文件中,我们可以自己定义全局变量(在全局作用域中使用set $var value),也可以在其他作用域中定义变量;

+

hiproxy内置了一些变量,这些内置变量可以在相应的作用域中直接使用,不需要去定义并赋值,而且这些内置变量也不能被用户重新定义覆盖。

+

全局变量

这些全局变量,在配置文件的任何地方都可以使用

+
+

提示:hiproxy暂时没有内置的全局变量。将来会添加!

+
+

location块级变量

这些变量,只能在location块中使用,这些变量主要是存储与请求相关的一些信息,比如请求的参数($query_string)、Cookie($cookie_name)和host($host)等。现在支持的所有内置变量:

+

$host

当前请求的URL对应的host或者请求头部的Host字段。

+

$hostname

当前请求的URL对应的hostname或者请求头部的Host字段对应的hostname

+

$server_port

请求的服务端口号,默认80

+

$search

请求的参数字符串(包括?),比如?from=app&v=19482848253

+

$query_string

请求的参数字符串(不包括?),比如from=app&v=19482848253

+

$scheme

请求的协议,http或者https

+

$request_uri

请求的完整地址,比如http://hiproxy.org:8081/docs/index.html?from=google&v=_1847295727524#get-started

+

$path

请求的path(包括参数),比如/docs/index.html?from=google&v=_1847295727524#get-started

+

$path_name

请求的path_name(不包括参数),比如/docs/index.html

+

$base_name

请求path的最后一部分,比如path为/docs/index.html,则$base_name为index.html

+

$dir_name

请求path的目录名称,比如path为/docs/index.html,则$dir_name为/docs/

+

$hash

请求url中的hash(包括#),比如’#get-started’。

+

$hash_value

请求url中的hash值(不包括#),比如’get-started’。

+

$uri

$request_uri

+

$cookie_name

cookie的值,name表示字段名称,这个名称中的大写字母都改成了小写,-替换成了_。比如$cookie_userId表示cookieuseId的值。

+

$http_name

请求头(request)中的字段值,name表示字段名称,这个名称中的大写字母都改成了小写,-替换成了_。比如请求头信息中包含User-Agent: user agent,可以使用变量$http_user_agent来获取这个值。

+

$arg_name

请求参数的值,name表示字段名称,这个名称中的大写字母都改成了小写,-替换成了_。比如请求参数为?from=google&v=_1847295727524,可以通过$arg_from来获取from的值。

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/rewrite/directives.html b/zh-cn/rewrite/directives.html new file mode 100644 index 0000000..5b723f1 --- /dev/null +++ b/zh-cn/rewrite/directives.html @@ -0,0 +1,312 @@ + + + + + rewrite指令 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

rewrite指令

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+ + +

指令

指令(也称:命令)用于设置变量,或者对request/response做一些操作。

+

全局指令

* set

描述:定义变量

+

语法:set key value

+

作用域链:global, domain, location

+

例子:

+
1
set $server hiipack;
+

代理请求相关指令

代理请求相关的指令,用于操作代理服务向目标服务器发送请求的Request对象。

+

作用域链:domain, location

+

* proxy_set_header

描述:设置请求头部字段

+

语法:proxy_set_header key value

+

例子:

+
1
proxy_set_header Host some.example.com;
+

* proxy_hide_header

描述:删除请求头部字段

+

语法:proxy_hide_header key

+

例子:

+
1
proxy_hide_header Host;
+

* proxy_set_cookie

描述:设置请求Cookie

+

语法:proxy_set_cookie key value

+

例子:

+
1
proxy_set_cookie from hiproxy;
+

* proxy_hide_cookie

描述:删除请求Cookie字段

+

语法:proxy_hide_cookie key

+

例子:

+
1
proxy_hide_cookie from;
+

* proxy_method

描述:设置请求方法(GET、POST等)

+

语法: proxy_method method

+

示例:

+
1
proxy_method POST;
+

* proxy_set_body

描述:设置请求的body内容.

+

语法: proxy_set_body body

+

示例:

+
1
proxy_set_body "a=1&b=2&c=3";
+

* proxy_append_body

描述:向请求的body追加内容.

+

语法: proxy_append_body content

+

示例:

+
1
proxy_append_body "&d=4";
+

* proxy_replace_body

描述:替换body中的部分内容.

+

语法: proxy_replace_body oldVal newVal

+

示例:

+
1
proxy_replace_body "a=1" "a=111";
+

代理响应相关指令

代理响应相关的指令用于配置代理服务器响应浏览器的Response对象。

+

作用域链:domain, location

+

* status

描述:设置相应状态码和消息

+

语法:status code message

+

例子:

+
1
status 477 "Authentication failed";
+

* set_header

描述:添加Header字段

+

语法:set_header key value

+

例子:

+
1
set_header SERVER hiproxy;
+

* hide_header

描述:删除Header字段

+

语法:hide_header key

+

例子

+
1
hide_header SERVER;
+

* set_cookie

描述:设置Cookie字段

+

语法:set_cookie key value

+

例子

+
1
set_cookie SESSION_ID 2BF36A09CB35FD71E;
+

* hide_cookie

描述:删除Cookie字段

+

语法:hide_cookie key

+

例子

+
1
hide_cookie SESSION_ID;
+

* send_file

描述:返回指定的文件

+

语法:send_file file_name

+

例子:

+
1
2
send_file index.html;
send_file /site/index.html;
+

* echo

描述:返回指定内容

+

语法:echo string

+

例子:

+
1
2
echo <h1>hello_echo</h1>;
echo <p>finish</p>;
+

domain内部指令

只在同一个domain内有效,且覆盖全局同名指令

+

作用域链:domain

+

* ssl_certificate

描述:手动指定证书文件

+

参数:ssl_certificate file.crt(只支持相对路径,后期完善)

+

例子:

+
1
2
3
example.com => {
ssl_certificate /user/root/.hiproxy/cert/example.crt;
}
+

* ssl_certificate_key

描述:手动指定私钥文件

+

参数:ssl_certificate_key file.key(只支持相对路径,后期完善)

+

例子:

+
1
2
3
example.com => {
ssl_certificate_key /user/root/.hiproxy/cert/example.key;
}
+

location内部指令

只在同一个location内有效,且覆盖全局及domain同名指令

+

作用域链:domain, location

+

* proxy_pass

描述:设置请求转发的目标地址

+

参数:proxy_pass url

+

例子:

+
1
proxy_pass http://some.example.com/some/path/;
+

* alias

描述:将对应的location映射到本地目录

+

参数:alias path

+

例子:

+
1
alias /Users/root/some/path/;
+

* root

描述:将对应的location映射到本地目录时的默认文件,默认文件名为index.html

+

参数:root file_name

+

例子

+
1
root app.html;
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/rewrite/index.html b/zh-cn/rewrite/index.html new file mode 100644 index 0000000..44b8240 --- /dev/null +++ b/zh-cn/rewrite/index.html @@ -0,0 +1,248 @@ + + + + + Rewrite简介 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

Rewrite简介

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

简介

rewrite 参考了Nginx配置语法,通过简单的配置,就可以帮助前端开发在本地调试的基础上,方便的利用其他环境或者线上的API接口进行测试。

+

当服务启动后,将自动扫描并监听各项目根目录下的rewrite文件,生成及实时更新转发规则,无需重启服务。

+

:hiproxy同时支持项目rewritehosts文件。如果仅需要简单的域名+端口转发,请参考hosts

+

基本语法

变量

语法 +

1
$变量名

+

例子

+
1
2
3
4
5
# 定义变量
set $var_name value

# 使用变量
$var_name
+

domain

domain 用来指定一个域名,这个域名的所有配置都在 domain 块中。

+

语法

+
1
2
3
[域名|变量] => {
# ...
}
+

例子

+
1
2
3
4
5
6
7
8
9
10
11
set $domain some.example.com

# 直接使用域名
some.example.com => {
# ...
}

# 或者使用变量
$domain => {
# ...
}
+

或者

+
1
2
3
4
5
6
7
8
9
10
11
set $domain some.example.com

# 直接使用域名
domain some.example.com {
# ...
}

# 或者使用变量
domain $domain {
# ...
}
+

location

location 用来指定域名中的一个具体的路径,这个路径的所有配置都在 location 块中。

+

注意:location必须位于domain块中。

+

语法

+
1
2
3
location [目录|文件|正则表达式|变量] {
# ...
}
+

例子

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 目录
location /some/path/ {
# ...
}

# 具体文件
location /some/file.htm {
# ...
}

# 正则表达式
location ~ ^/some/(path|path1)/.* {
# ...
}

# 变量
location $some/$path {
# ...
}
+

命令

命令用于设置一些变量,或者对request\/response做一些操作。

+

语法

+
1
命令 参数1 参数2 ... 参数N
+

例子

+
1
2
3
4
5
# 设置代理时的头部
proxy_set_header Host some.example.com;

# 设置response的cookie
set_cookie UserID some_user_id;
+

注释

用来注释某些不需要的内容,只支持单行注释

+

语法

+
1
# 注释内容
+

简写语法

简写语法,可以用来定义一些基本的规则,不需要写location和其他的命令。

+

语法

+
1
域名 ==> 域名|路径
+

例子

+
1
json.example.com => 127.0.0.1:8800;
+

更多例子

1
2
3
4
5
set $local 127.0.0.1:8800
# simple rewrite rule
api.hiproxy.org => local.hiproxy.org;
api.hiproxy.org => 127.0.0.1:8800;
api.hiproxy.org/mock => $local/mock;
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# rewrite folder
api.hiproxy.org/user/ => {
proxy_pass local.hiproxy.org/user/;

# proxy request config
proxy_set_header Host api.hiproxy.org;
proxy_set_header other value;
proxy_hide_header other;

proxy_set_cookie userid 20150910121359;
proxy_hide_cookie sessionid;

# response config
set_cookie sessionID E3BF86A90ACDD6C5FF49ACB09;
set_header proxy hiproxy;

# allow CORS
set_header Access-Control-Allow-Origin *;

hide_header proxy;
hide_cookie sessionID;
}
+
1
2
3
4
# regexp support
~ /(demo|example)/([^\/]*\.(html|htm))$ => {
proxy_pass http://127.0.0.1:9999/$1/src/$2;
}
+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
set $domain api.hiproxy.org;
set $local 127.0.0.1:8800;
set $api api;
set $test $api.example.com;
set $id 1234567;

# standard rewrite url
$domain => {
proxy_pass http://$local/api/mock/;
set $id 1234;
set $mock_user user_$id;
set_header Host $domain;
set_header UserID $mock_user;
set_header Access-Control-Allow-Origin *;
}

blog.hiproxy.org => {
set_header Access-Control-Allow-Origin *;

set $node_server 127.0.0.1:3008;
set $order order;
set $cookie1 login=true;expires=20160909;

location /$api/$order/detail {
proxy_pass http://$node_server/user/?domain=$domain;
set_header Set-Cookie userID 200908204140;
}

location ~ /(usercenter|userinfo)/ {
set $cookie login=true;expires=20180808;
set $id 56789;

proxy_pass http://127.0.0.1:3008/info/;

set_cookie userID 200908204140;
set_cookie userName user_$id;
}

location ~ /local\/(.*)(\?(.*))? {
send_file ./mock/$1.json;
}

location /dev {
#alias /site/path/;
alias ./src/view/;
root app.html
}

location /multiple {
echo <h1>hello_echo</h1>;
echo <p>test echo directive</p>;
echo <p>finish</p>;
}

}
+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file diff --git a/zh-cn/rewrite/scope.html b/zh-cn/rewrite/scope.html new file mode 100644 index 0000000..6c42884 --- /dev/null +++ b/zh-cn/rewrite/scope.html @@ -0,0 +1,237 @@ + + + + + 作用域 | hiproxy documentation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+
+
+
+
+
+
+

作用域

+ +
+
+
+

如果你愿意帮助hiproxy编写文档,请联系zdying@live.com, 谢谢!

+

If you are willing to help hiproxy to write documentation, please contact zdying@live.com, thank you!

+
+

代码块

hiproxy的代码块,分为三类:

+
    +
  • 全局块:所有的配置文件中不在其他块的代码,都在全局块中;
  • +
  • domain块:位于全局块中;
  • +
  • location块:位于domain块中;
  • +
+

作用域

hiproxy 配置文件中涉及到的作用域有5种:

+
    +
  • 全局作用域全局块对应的作用域。这里的变量可以在任何地方访问到;
  • +
  • domain作用域domain块对应的作用域。
  • +
  • location作用域location块对应的作用域。
  • +
  • request作用域:隐式作用域,不对应具体的代码块,这些作用域中的指令,可以分布在任何代码块中。
  • +
  • response作用域:隐式作用域,不对应具体的代码块,这些作用域中的指令,可以分布在任何代码块中。
  • +
+

代码块层级关系

1
2
3
4
5
6
7
8
9
global
|- domain
|- location
|- location
|- ...
|- domain
|- location
|- location
|- ...
+

变量查找

当前作用域中查找变量的规则为:

+
    +
  1. 如果当前作用域有这个变量,返回 这个变量的值。
  2. +
  3. 查找上一级作用域,如果上一级作用域中有这个变量,返回 这个变量的值。
  4. +
  5. 否则,如果上一级作用域是全局作用域,返回 变量名称(包括$符号)。
  6. +
  7. 重复步骤[2-3]
  8. +
+

指令执行

代码块中的指令在对应的时机(request/response)会自动执行,此外,还会执行上一级代码块中的指令,比如:

+
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
www1.test.com => {
# 1
proxy_set_header Host www.test.com;

location / {
# 2
proxy_pass http://52.88.88.88/;
}

location /index.html {
# 3
proxy_pass http://127.0.0.1:8800/girl/view/index.html;
}

location ~ /\/(native|gallery|picture|font)\/(.*)/ {
# 4
proxy_pass http://88.88.88.88/$1/$2;
}
}
+

上面的配置中,在执行#2、#3和#4处的指令同时,都会执行配置在#1处的指令,也就是说:

+

//index.html/\/(native|gallery|picture|font)\/(.*)/对应的请求,都会加上请求头部Host,值为www.test.com

+ +
+
+ + +
+ +
+
+
+ + +
+
+ +
+
+ +
+
+
+ + + +
+
+ + + + + + + + + + \ No newline at end of file