README.md 13.6 KB
Newer Older
F
fatedier 已提交
1
# frp
2

F
fatedier 已提交
3
[![Build Status](https://travis-ci.org/fatedier/frp.svg?branch=master)](https://travis-ci.org/fatedier/frp)
4

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
    * [Access your computer in LAN by SSH](#access-your-computer-in-lan-by-ssh)
F
fatedier 已提交
19 20
    * [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 22
    * [Forward unix domain socket](#forward-unix-domain-socket)
    * [Connect website through frpc's network](#connect-website-through-frpcs-network)
F
fatedier 已提交
23
* [Features](#features)
F
fatedier 已提交
24 25 26 27 28 29
    * [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)
F
fatedier 已提交
30
    * [TCP Stream Multiplexing](#tcp-stream-multiplexing)
F
fatedier 已提交
31
    * [Support KCP Protocol](#support-kcp-protocol)
F
fatedier 已提交
32 33 34 35
    * [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)
F
fatedier 已提交
36
    * [URL routing](#url-routing)
F
fatedier 已提交
37
    * [Connect frps by HTTP PROXY](#connect-frps-by-http-proxy)
F
fatedier 已提交
38
    * [Plugin](#plugin)
F
fatedier 已提交
39 40
* [Development Plan](#development-plan)
* [Contributing](#contributing)
F
fatedier 已提交
41
* [Donation](#donation)
F
fatedier 已提交
42
    * [AliPay](#alipay)
F
fatedier 已提交
43
    * [Wechat Pay](#wechat-pay)
F
fatedier 已提交
44
    * [Paypal](#paypal)
F
fatedier 已提交
45

F
fatedier 已提交
46 47
<!-- vim-markdown-toc -->

F
fatedier 已提交
48 49
## What can I do with frp?

F
fatedier 已提交
50
* 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 已提交
51
* Expose any tcp or udp service behind a NAT or firewall to the internet by a server with public IP address.
F
fatedier 已提交
52

F
fatedier 已提交
53 54
## Status

E
Eric Larssen 已提交
55
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 已提交
56

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

F
fatedier 已提交
59
## Architecture
F
fatedier 已提交
60

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

F
fatedier 已提交
63
## Example Usage
F
fatedier 已提交
64

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

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

F
fatedier 已提交
69 70
Put **frpc** and **frpc.ini** to your server in LAN.

F
fatedier 已提交
71
### Access your computer in LAN by SSH
F
fatedier 已提交
72

F
fatedier 已提交
73
1. Modify frps.ini:
F
fatedier 已提交
74 75 76 77 78 79 80 81 82 83 84

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

2. Start frps:

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

F
fatedier 已提交
85
3. Modify frpc.ini, `server_addr` is your frps's server IP:
F
fatedier 已提交
86 87 88 89 90 91 92 93

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

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

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 已提交
108
### Visit your web service in LAN by custom domains
F
fatedier 已提交
109

F
fatedier 已提交
110
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 已提交
111

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

F
fatedier 已提交
114
1. Modify frps.ini, configure http port 8080:
F
fatedier 已提交
115 116 117 118 119 120 121 122 123 124 125 126

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

2. Start frps:

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

F
fatedier 已提交
127
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 已提交
128 129 130 131 132 133 134 135 136 137

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

  [web]
  type = http
  local_port = 80
F
fatedier 已提交
138
  custom_domains = www.yourdomain.com
F
fatedier 已提交
139 140 141 142 143 144
  ```

4. Start frpc:

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

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

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

F
fatedier 已提交
149 150
### Forward DNS query request

F
fatedier 已提交
151
1. Modify frps.ini:
F
fatedier 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174

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

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

  [dns]
  type = udp
  local_ip = 8.8.8.8
  local_port = 53
F
fatedier 已提交
175
  remote_port = 6000
F
fatedier 已提交
176 177 178 179 180 181 182 183 184 185
  ```

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 已提交
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
### Forward unix domain socket

Using tcp port to connect unix domain socket like docker daemon.

1. Modify frps.ini:

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

2. Start frps:

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

3. Modify frpc.ini:

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

  [unix_domain_socket]
  type = tcp
  remote_port = 6000
  plugin = unix_domain_socket
  plugin_unix_path = /var/run/docker.sock
  ```

4. Start frpc:

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

5. Get docker version by curl command:

  `curl http://x.x.x.x:6000/version`

### Connect website through frpc's network

Configure frps same as above.

1. Modify frpc.ini:

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

  [http_proxy]
  type = tcp
  remote_port = 6000
F
fatedier 已提交
240
  plugin = http_proxy # or socks5
F
fatedier 已提交
241 242 243 244 245 246
  ```

4. Start frpc:

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

F
fatedier 已提交
247
5. Set http proxy or socks5 proxy `x.x.x.x:6000` in your browser and visit website through frpc's network.
F
fatedier 已提交
248

F
fatedier 已提交
249 250
## Features

F
fatedier 已提交
251 252 253 254 255 256 257 258 259
### 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 已提交
260
# dashboard's username and password are both optional,if not set, default is admin.
F
fatedier 已提交
261 262
dashboard_user = admin
dashboard_pwd = admin
F
fatedier 已提交
263 264
```

E
Eric Larssen 已提交
265
Then visit `http://[server_addr]:7500` to see dashboard, default username and password are both `admin`.
F
fatedier 已提交
266 267 268

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

F
fatedier 已提交
269 270
### Authentication

F
fatedier 已提交
271
Since v0.10.0, you only need to set `privilege_token` in frps.ini and frpc.ini.
F
fatedier 已提交
272

F
fatedier 已提交
273
Note that time duration between server of frpc and frps mustn't exceed 15 minutes because timestamp is used for authentication.
F
fatedier 已提交
274

F
fatedier 已提交
275 276
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 已提交
277 278
### Encryption and Compression

F
fatedier 已提交
279
Defalut value is false, you could decide if the proxy will use encryption or compression:
F
fatedier 已提交
280 281 282 283 284

```ini
# frpc.ini
[ssh]
type = tcp
F
fatedier 已提交
285 286
local_port = 22
remote_port = 6000
F
fatedier 已提交
287
use_encryption = true
F
fatedier 已提交
288
use_compression = true
F
fatedier 已提交
289 290 291 292
```

### Reload configures without frps stopped

F
fatedier 已提交
293
This feature is removed since v0.10.0.
F
fatedier 已提交
294 295 296

### Privilege Mode

F
fatedier 已提交
297
Privilege mode is the default and only mode support in frp since v0.10.0. All proxy configurations are set in client.
F
fatedier 已提交
298

F
fatedier 已提交
299 300
#### Port White List

F
fatedier 已提交
301
`privilege_allow_ports` in frps.ini is used for preventing abuse of ports:
F
fatedier 已提交
302 303 304 305 306 307 308

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

F
fatedier 已提交
309
`privilege_allow_ports` consists of a specific port or a range of ports divided by `,`.
F
fatedier 已提交
310

F
fatedier 已提交
311 312 313 314 315 316 317 318 319 320 321 322
### TCP Stream Multiplexing

frp support tcp stream multiplexing since v0.10.0 like HTTP2 Multiplexing. All user requests to same frpc can use only one tcp connection.

You can disable this feature by modify frps.ini and frpc.ini:

```ini
# frps.ini and frpc.ini, must be same
[common]
tcp_mux = false
```

F
fatedier 已提交
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351
### Support KCP Protocol

frp support kcp protocol since v0.12.0.

KCP is a fast and reliable protocol that can achieve the transmission effect of a reduction of the average latency by 30% to 40% and reduction of the maximum delay by a factor of three, at the cost of 10% to 20% more bandwidth wasted than TCP.

Using kcp in frp:

1. Enable kcp protocol in frps:

  ```ini
  # frps.ini
  [common]
  bind_port = 7000
  # kcp needs to bind a udp port, it can be same with 'bind_port'
  kcp_bind_port = 7000
  ```

2. Configure the protocol used in frpc to connect frps:

  ```ini
  # frpc.ini
  [common]
  server_addr = x.x.x.x
  # specify the 'kcp_bind_port' in frps
  server_port = 7000
  protocol = kcp
  ```

F
fatedier 已提交
352 353 354 355 356 357 358 359
### 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:

F
fatedier 已提交
360
  ```ini
F
fatedier 已提交
361 362
  # frps.ini
  [common]
F
fatedier 已提交
363
  max_pool_count = 5
F
fatedier 已提交
364 365 366 367
  ```

2. Enable and specify the number of connection pool:

E
Eric Larssen 已提交
368
  ```ini
F
fatedier 已提交
369
  # frpc.ini
F
fatedier 已提交
370 371
  [common]
  pool_count = 1
F
fatedier 已提交
372 373 374 375 376 377
  ```

### 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.

F
fatedier 已提交
378 379
```ini
# frpc.ini
E
Eric Larssen 已提交
380
[web]
F
fatedier 已提交
381 382 383 384 385 386 387 388
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 已提交
389 390 391 392 393 394
### 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.

F
fatedier 已提交
395
It can only be enabled when proxy type is http.
F
fatedier 已提交
396 397 398 399 400 401 402 403 404 405 406

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

F
fatedier 已提交
407
Visit `http://test.yourdomain.com` and now you need to input username and password.
F
fatedier 已提交
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431

### 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]
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`.

F
fatedier 已提交
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
### URL routing

frp support forward http requests to different backward web services by url routing.

`locations` specify the prefix of URL used for routing. frps first searches for the most specific prefix location given by literal strings regardless of the listed order.

```ini
# frpc.ini
[web01]
type = http
local_port = 80
custom_domains = web.yourdomain.com
locations = /

[web02]
type = http
local_port = 81
custom_domains = web.yourdomain.com
locations = /news,/about
```
Http requests with url prefix `/news` and `/about` will be forwarded to **web02** and others to **web01**.

F
fatedier 已提交
454 455 456 457
### 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.

F
fatedier 已提交
458 459
It only works when protocol is tcp.

F
fatedier 已提交
460 461
```ini
# frpc.ini
F
fatedier 已提交
462
[common]
F
fatedier 已提交
463 464 465 466 467
server_addr = x.x.x.x
server_port = 7000
http_proxy = http://user:pwd@192.168.1.128:8080
```

F
fatedier 已提交
468 469 470 471
### Plugin

frpc only forward request to local tcp or udp port by default.

F
fatedier 已提交
472
Plugin is used for providing rich features. There are built-in plugins such as **unix_domain_socket**, **http_proxy**, **socks5** and you can see [example usage](#example-usage).
F
fatedier 已提交
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490

Specify which plugin to use by `plugin` parameter. Configuration parameters of plugin should be started with `plugin_`. `local_ip` and `local_port` is useless for plugin.

Using plugin **http_proxy**:

```ini
# frpc.ini
[http_proxy]
type = tcp
remote_port = 6000
plugin = http_proxy
plugin_http_user = abc
plugin_http_passwd = abc
```

`plugin_http_user` and `plugin_http_passwd` are configuration parameters used in `http_proxy` plugin.


F
fatedier 已提交
491 492
## Development Plan

F
fatedier 已提交
493 494
* Log http request information in frps.
* Direct reverse proxy, like haproxy.
F
fatedier 已提交
495
* Load balance to different service in frpc.
F
fatedier 已提交
496
* Frpc can directly be a webserver for static files.
F
fatedier 已提交
497
* P2p communicate by make udp hole to penetrate NAT.
F
fatedier 已提交
498 499
* kubernetes ingress support.

500 501 502

## Contributing

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

F
fatedier 已提交
505 506 507
* 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 已提交
508
* If you have some wanderful ideas, send email to fatedier@gmail.com.
F
fatedier 已提交
509

F
fatedier 已提交
510 511
**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 已提交
512 513 514 515
## Donation

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

F
fatedier 已提交
516 517
frp QQ group: 606194980

F
fatedier 已提交
518 519 520 521
### AliPay

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

F
fatedier 已提交
522 523 524 525
### Wechat Pay

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

F
fatedier 已提交
526 527 528
### Paypal

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