README.md 12.5 KB
Newer Older
F
fatedier 已提交
1
# frp
2 3 4

[![Build Status](https://travis-ci.org/fatedier/frp.svg)](https://travis-ci.org/fatedier/frp)

F
fatedier 已提交
5 6
[README](README.md) | [中文文档](README_zh.md)

F
fatedier 已提交
7 8
## What is frp?

F
fatedier 已提交
9
frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet. Now, it supports tcp, udp, http and https protocol when requests can be forwarded by domains to backward web services.
F
fatedier 已提交
10

F
fatedier 已提交
11
## Table of Contents
F
fatedier 已提交
12

F
fatedier 已提交
13
<!-- vim-markdown-toc GFM -->
F
fatedier 已提交
14 15 16
* [What can I do with frp?](#what-can-i-do-with-frp)
* [Status](#status)
* [Architecture](#architecture)
E
Eric Larssen 已提交
17
* [Example Usage](#example-usage)
F
fatedier 已提交
18 19 20
    * [Communicate with your computer in LAN by SSH](#communicate-with-your-computer-in-lan-by-ssh)
    * [Visit your web service in LAN by custom domains](#visit-your-web-service-in-lan-by-custom-domains)
    * [Forward DNS query request](#forward-dns-query-request)
F
fatedier 已提交
21
* [Features](#features)
F
fatedier 已提交
22 23 24 25 26 27 28 29 30 31 32
    * [Dashboard](#dashboard)
    * [Authentication](#authentication)
    * [Encryption and Compression](#encryption-and-compression)
    * [Reload configures without frps stopped](#reload-configures-without-frps-stopped)
    * [Privilege Mode](#privilege-mode)
        * [Port White List](#port-white-list)
    * [Connection Pool](#connection-pool)
    * [Rewriting the Host Header](#rewriting-the-host-header)
    * [Password protecting your web service](#password-protecting-your-web-service)
    * [Custom subdomain names](#custom-subdomain-names)
    * [Connect frps by HTTP PROXY](#connect-frps-by-http-proxy)
F
fatedier 已提交
33 34
* [Development Plan](#development-plan)
* [Contributing](#contributing)
F
fatedier 已提交
35
* [Donation](#donation)
F
fatedier 已提交
36 37
    * [AliPay](#alipay)
    * [Paypal](#paypal)
F
fatedier 已提交
38
* [Contributors](#contributors)
F
fatedier 已提交
39

F
fatedier 已提交
40 41
<!-- vim-markdown-toc -->

F
fatedier 已提交
42 43
## What can I do with frp?

F
fatedier 已提交
44
* Expose any http and https service behind a NAT or firewall to the internet by a server with public IP address(Name-based Virtual Host Support).
F
fatedier 已提交
45 46 47
* Expose any tcp service behind a NAT or firewall to the internet by a server with public IP address.
* Inspect all http requests/responses that are transmitted over the tunnel(future).

F
fatedier 已提交
48 49
## Status

E
Eric Larssen 已提交
50
frp is under development and you can try it with latest release version. Master branch for releasing stable version when dev branch for developing.
F
fatedier 已提交
51

E
Eric Larssen 已提交
52
**We may change any protocol and can't promise backward compatible. Please check the release log when upgrading.**
F
fatedier 已提交
53

F
fatedier 已提交
54
## Architecture
F
fatedier 已提交
55

F
fatedier 已提交
56
![architecture](/doc/pic/architecture.png)
F
fatedier 已提交
57

F
fatedier 已提交
58
## Example Usage
F
fatedier 已提交
59

F
fatedier 已提交
60
Firstly, download the latest programs from [Release](https://github.com/fatedier/frp/releases) page according to your os and arch.
F
fatedier 已提交
61

F
fatedier 已提交
62
Put **frps** and **frps.ini** to your server with public IP.
F
fatedier 已提交
63

F
fatedier 已提交
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
Put **frpc** and **frpc.ini** to your server in LAN.

### Communicate with your computer in LAN by SSH

1. Modify frps.ini, configure a reverse proxy named [ssh]:

  ```ini
  # frps.ini
  [common]
  bind_port = 7000

  [ssh]
  listen_port = 6000
  auth_token = 123
  ```

2. Start frps:

  `./frps -c ./frps.ini`

3. Modify frpc.ini, set remote frps's server IP as x.x.x.x:

  ```ini
  # frpc.ini
  [common]
  server_addr = x.x.x.x
  server_port = 7000
  auth_token = 123

  [ssh]
F
fatedier 已提交
94 95
  type = tcp
  local_ip = 127.0.0.1
F
fatedier 已提交
96 97 98 99 100 101 102 103 104 105 106
  local_port = 22
  ```

4. Start frpc:

  `./frpc -c ./frpc.ini`

5. Connect to server in LAN by ssh assuming that username is test:

  `ssh -oPort=6000 test@x.x.x.x`

F
fatedier 已提交
107
### Visit your web service in LAN by custom domains
F
fatedier 已提交
108

F
fatedier 已提交
109
Sometimes we want to expose a local web service behind a NAT network to others for testing with your own domain name and unfortunately we can't resolve a domain name to a local ip.
F
fatedier 已提交
110

F
fatedier 已提交
111
However, we can expose a http or https service using frp.
F
fatedier 已提交
112

F
fatedier 已提交
113
1. Modify frps.ini, configure a http reverse proxy named [web] and set http port as 8080, custom domain as `www.yourdomain.com`:
F
fatedier 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130

  ```ini
  # frps.ini
  [common]
  bind_port = 7000
  vhost_http_port = 8080

  [web]
  type = http
  custom_domains = www.yourdomain.com
  auth_token = 123
  ```

2. Start frps:

  `./frps -c ./frps.ini`

F
fatedier 已提交
131
3. Modify frpc.ini and set remote frps server's IP as x.x.x.x. The `local_port` is the port of your web service:
F
fatedier 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148

  ```ini
  # frpc.ini
  [common]
  server_addr = x.x.x.x
  server_port = 7000
  auth_token = 123

  [web]
  type = http
  local_port = 80
  ```

4. Start frpc:

  `./frpc -c ./frpc.ini`

F
fatedier 已提交
149
5. Resolve A record of `www.yourdomain.com` to IP `x.x.x.x` or CNAME record to your origin domain.
F
fatedier 已提交
150

F
fatedier 已提交
151
6. Now visit your local web service using url `http://www.yourdomain.com:8080`.
F
fatedier 已提交
152

F
fatedier 已提交
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
### Forward DNS query request

1. Modify frps.ini, configure a reverse proxy named [dns]:

  ```ini
  # frps.ini
  [common]
  bind_port = 7000

  [dns]
  type = udp
  listen_port = 6000
  auth_token = 123
  ```

2. Start frps:

  `./frps -c ./frps.ini`

3. Modify frpc.ini, set remote frps's server IP as x.x.x.x, forward dns query request to google dns server `8.8.8.8:53`:

  ```ini
  # frpc.ini
  [common]
  server_addr = x.x.x.x
  server_port = 7000
  auth_token = 123

  [dns]
  type = udp
  local_ip = 8.8.8.8
  local_port = 53
  ```

4. Start frpc:

  `./frpc -c ./frpc.ini`

5. Send dns query request by dig:

  `dig @x.x.x.x -p 6000 www.goolge.com`

F
fatedier 已提交
195 196
## Features

F
fatedier 已提交
197 198 199 200 201 202 203 204 205
### Dashboard

Check frp's status and proxies's statistics information by Dashboard.

Configure a port for dashboard to enable this feature:

```ini
[common]
dashboard_port = 7500
E
Eric Larssen 已提交
206
# dashboard's username and password are both optional,if not set, default is admin.
F
fatedier 已提交
207 208
dashboard_user = admin
dashboard_pwd = admin
F
fatedier 已提交
209 210
```

E
Eric Larssen 已提交
211
Then visit `http://[server_addr]:7500` to see dashboard, default username and password are both `admin`.
F
fatedier 已提交
212 213 214

![dashboard](/doc/pic/dashboard.png)

F
fatedier 已提交
215 216
### Authentication

F
fatedier 已提交
217
`auth_token` in frps.ini is configured for each proxy and check for authentication when frpc login in.
F
fatedier 已提交
218

F
fatedier 已提交
219
Client that want's to register must set a global `auth_token` equals to frps.ini.
F
fatedier 已提交
220

F
fatedier 已提交
221
Note that time duration bewtween frpc and frps mustn't exceed 15 minutes because timestamp is used for authentication.
F
fatedier 已提交
222

F
fatedier 已提交
223 224
Howerver, this timeout duration can be modified by setting `authentication_timeout` in frps's configure file. It's defalut value is 900, means 15 minutes. If it is equals 0, then frps will not check authentication timeout.

F
fatedier 已提交
225 226
### Encryption and Compression

F
fatedier 已提交
227
Defalut value is false, you could decide if the proxy will use encryption or compression whether the type is:
F
fatedier 已提交
228 229 230 231 232 233 234 235 236 237 238 239 240

```ini
# frpc.ini
[ssh]
type = tcp
listen_port = 6000
auth_token = 123
use_encryption = true
use_gzip = true
```

### Reload configures without frps stopped

F
fatedier 已提交
241
If you want to add a new reverse proxy and avoid restarting frps, you can use this function:
F
fatedier 已提交
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278

1. `dashboard_port` should be set in frps.ini:

  ```ini
  # frps.ini
  [common]
  bind_port = 7000
  dashboard_port = 7500
  ```

2. Start frps:

  `./frps -c ./frps.ini`

3. Modify frps.ini to add a new proxy [new_ssh]:

  ```ini
  # frps.ini
  [common]
  bind_port = 7000
  dashboard_port = 7500

  [new_ssh]
  listen_port = 6001
  auth_token = 123
  ```

4. Execute `reload` command:

  `./frps -c ./frps.ini --reload`

5. Start frpc and [new_ssh] is available now.

### Privilege Mode

Privilege mode is used for who don't want to do operations in frps everytime adding a new proxy.

F
fatedier 已提交
279
All proxies's configurations are set in frpc.ini when privilege mode is enabled.
F
fatedier 已提交
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313

1. Enable privilege mode and set `privilege_token`.Client with the same `privilege_token` can create proxy automaticly:

  ```ini
  # frps.ini
  [common]
  bind_port = 7000
  privilege_mode = true
  privilege_token = 1234
  ```

2. Start frps:

  `./frps -c ./frps.ini`

3. Enable privilege mode for proxy [ssh]:

  ```ini
  # frpc.ini
  [common]
  server_addr = x.x.x.x
  server_port = 7000
  privilege_token = 1234

  [ssh]
  privilege_mode = true
  local_port = 22
  remote_port = 6000
  ```

4. Start frpc:

  `./frpc -c ./frpc.ini`

F
fatedier 已提交
314
5. Connect to server in LAN by ssh assuming username is test:
F
fatedier 已提交
315 316 317

  `ssh -oPort=6000 test@x.x.x.x`

F
fatedier 已提交
318 319 320 321 322 323 324 325 326 327 328 329
#### Port White List

`privilege_allow_ports` in frps.ini is used for preventing abuse of ports in privilege mode:

```ini
# frps.ini
[common]
privilege_mode = true
privilege_token = 1234
privilege_allow_ports = 2000-3000,3001,3003,4000-50000
```

F
fatedier 已提交
330
`privilege_allow_ports` consists of a specific port or a range of ports divided by `,`.
F
fatedier 已提交
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347

### Connection Pool

By default, frps send message to frpc for create a new connection to backward service when getting an user request.If a proxy's connection pool is enabled, there will be a specified number of connections pre-established.

This feature is fit for a large number of short connections.

1. Configure the limit of pool count each proxy can use in frps.ini:

  ```ini         
  # frps.ini
  [common]
  max_pool_count = 50
  ```

2. Enable and specify the number of connection pool:

E
Eric Larssen 已提交
348
  ```ini
F
fatedier 已提交
349
  # frpc.ini
E
Eric Larssen 已提交
350
  [ssh]
F
fatedier 已提交
351 352 353 354 355 356 357 358 359 360 361
  type = tcp
  local_port = 22
  pool_count = 10
  ```

### Rewriting the Host Header

When forwarding to a local port, frp does not modify the tunneled HTTP requests at all, they are copied to your server byte-for-byte as they are received. Some application servers use the Host header for determining which development site to display. For this reason, frp can rewrite your requests with a modified Host header. Use the `host_header_rewrite` switch to rewrite incoming HTTP requests.

```ini                                                             
# frpc.ini                                                         
E
Eric Larssen 已提交
362
[web]
F
fatedier 已提交
363 364 365 366 367 368 369 370 371
privilege_mode = true
type = http
local_port = 80
custom_domains = test.yourdomain.com
host_header_rewrite = dev.yourdomain.com
```

If `host_header_rewrite` is specified, the Host header will be rewritten to match the hostname portion of the forwarding address.

F
fatedier 已提交
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427
### Password protecting your web service

Anyone who can guess your tunnel URL can access your local web server unless you protect it with a password.

This enforces HTTP Basic Auth on all requests with the username and password you specify in frpc's configure file.

It can be only enabled when proxy type is http.

```ini
# frpc.ini
[web]
privilege_mode = true
type = http
local_port = 80
custom_domains = test.yourdomain.com
http_user = abc
http_pwd = abc
```

Visit `test.yourdomain.com` and now you need to input username and password.

### Custom subdomain names

It is convenient to use `subdomain` configure for http、https type when many people use one frps server together.

```ini
# frps.ini
subdomain_host = frps.com
```

Resolve `*.frps.com` to the frps server's IP.

```ini
# frpc.ini
[web]
privilege_mode = true
type = http
local_port = 80
subdomain = test
```

Now you can visit your web service by host `test.frps.com`.

Note that if `subdomain_host` is not empty, `custom_domains` should not be the subdomain of `subdomain_host`.

### Connect frps by HTTP PROXY

frpc can connect frps using HTTP PROXY if you set os environment `HTTP_PROXY` or configure `http_proxy` param in frpc.ini file.

```ini
# frpc.ini
server_addr = x.x.x.x
server_port = 7000
http_proxy = http://user:pwd@192.168.1.128:8080
```

F
fatedier 已提交
428 429 430
## Development Plan

* Url router.
F
fatedier 已提交
431 432
* Log http request information in frps.
* Direct reverse proxy, like haproxy.
F
fatedier 已提交
433 434 435
* Load balance to different service in frpc.
* Debug mode for frpc, prestent proxy status in terminal.
* Inspect all http requests/responses that are transmitted over the tunnel.
F
fatedier 已提交
436 437
* Frpc can directly be a webserver for static files.
* Full control mode, dynamically modify frpc's configure with dashboard in frps.
F
fatedier 已提交
438
* P2p communicate by make udp hole to penetrate NAT.
439 440 441

## Contributing

F
fatedier 已提交
442
Interested in getting involved? We would like to help you!
443

F
fatedier 已提交
444 445 446
* Take a look at our [issues list](https://github.com/fatedier/frp/issues) and consider sending a Pull Request to **dev branch**.
* If you want to add a new feature, please create an issue first to describe the new feature, as well as the implementation approach. Once a proposal is accepted, create an implementation of the new features and submit it as a pull request.
* Sorry for my poor english and improvement for this document is welcome even some typo fix.
F
fatedier 已提交
447
* If you have some wanderful ideas, send email to fatedier@gmail.com.
F
fatedier 已提交
448

F
fatedier 已提交
449 450
**Note: We prefer you to give your advise in [issues](https://github.com/fatedier/frp/issues), so others with a same question can search it quickly and we don't need to answer them repeatly.**

F
fatedier 已提交
451 452 453 454
## Donation

If frp help you a lot, you can support us by:

F
fatedier 已提交
455 456
frp QQ group: 606194980

F
fatedier 已提交
457 458 459 460 461 462 463 464
### AliPay

![donation-alipay](/doc/pic/donate-alipay.png)

### Paypal

Donate money by [paypal](https://www.paypal.me/fatedier) to my account **fatedier@gmail.com**.

F
fatedier 已提交
465 466 467 468
## Contributors

* [fatedier](https://github.com/fatedier)
* [Hurricanezwf](https://github.com/Hurricanezwf)
F
fatedier 已提交
469 470 471 472 473
* [Pan Hao](https://github.com/vashstorm)
* [Danping Mao](https://github.com/maodanp)
* [Eric Larssen](https://github.com/ericlarssen)
* [Damon Zhao](https://github.com/se77en)
* [Manfred Touron](https://github.com/moul)
F
fatedier 已提交
474
* [xuebing1110](https://github.com/xuebing1110)