README.md 20.4 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?

9
frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet. As of now, it supports tcp & udp, as well as http and https protocols, where requests can be forwarded to internal services by domain name.
F
fatedier 已提交
10

F
fatedier 已提交
11 12
Now it also try to support p2p connect.

F
fatedier 已提交
13
## Table of Contents
F
fatedier 已提交
14

F
fatedier 已提交
15
<!-- vim-markdown-toc GFM -->
F
fatedier 已提交
16

F
fatedier 已提交
17 18
* [Status](#status)
* [Architecture](#architecture)
E
Eric Larssen 已提交
19
* [Example Usage](#example-usage)
F
fatedier 已提交
20
    * [Access your computer in LAN by SSH](#access-your-computer-in-lan-by-ssh)
F
fatedier 已提交
21 22
    * [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 已提交
23
    * [Forward unix domain socket](#forward-unix-domain-socket)
F
fatedier 已提交
24
    * [Expose a simple http file server](#expose-a-simple-http-file-server)
F
fatedier 已提交
25
    * [Enable HTTPS for local HTTP service](#enable-https-for-local-http-service)
F
fatedier 已提交
26
    * [Expose your service in security](#expose-your-service-in-security)
F
fatedier 已提交
27
    * [P2P Mode](#p2p-mode)
F
fatedier 已提交
28
* [Features](#features)
F
fatedier 已提交
29
    * [Configuration File](#configuration-file)
F
fatedier 已提交
30
    * [Configuration file template](#configuration-file-template)
F
fatedier 已提交
31
    * [Dashboard](#dashboard)
F
fatedier 已提交
32
    * [Admin UI](#admin-ui)
F
fatedier 已提交
33 34
    * [Authentication](#authentication)
    * [Encryption and Compression](#encryption-and-compression)
F
fatedier 已提交
35
        * [TLS](#tls)
F
fatedier 已提交
36
    * [Hot-Reload frpc configuration](#hot-reload-frpc-configuration)
F
fatedier 已提交
37
    * [Get proxy status from client](#get-proxy-status-from-client)
F
fatedier 已提交
38
    * [Port White List](#port-white-list)
F
fatedier 已提交
39
    * [Port Reuse](#port-reuse)
F
fatedier 已提交
40
    * [TCP Stream Multiplexing](#tcp-stream-multiplexing)
F
fatedier 已提交
41
    * [Support KCP Protocol](#support-kcp-protocol)
F
fatedier 已提交
42
    * [Connection Pool](#connection-pool)
F
fatedier 已提交
43
    * [Load balancing](#load-balancing)
F
fatedier 已提交
44
    * [Health Check](#health-check)
F
fatedier 已提交
45
    * [Rewriting the Host Header](#rewriting-the-host-header)
F
fatedier 已提交
46
    * [Set Headers In HTTP Request](#set-headers-in-http-request)
F
fatedier 已提交
47
    * [Get Real IP](#get-real-ip)
F
fatedier 已提交
48 49
        * [HTTP X-Forwarded-For](#http-x-forwarded-for)
        * [Proxy Protocol](#proxy-protocol)
F
fatedier 已提交
50 51
    * [Password protecting your web service](#password-protecting-your-web-service)
    * [Custom subdomain names](#custom-subdomain-names)
F
fatedier 已提交
52
    * [URL routing](#url-routing)
F
fatedier 已提交
53
    * [Connect frps by HTTP PROXY](#connect-frps-by-http-proxy)
F
fatedier 已提交
54
    * [Range ports mapping](#range-ports-mapping)
F
fatedier 已提交
55
    * [Plugin](#plugin)
F
fatedier 已提交
56 57
* [Development Plan](#development-plan)
* [Contributing](#contributing)
F
fatedier 已提交
58
* [Donation](#donation)
F
fatedier 已提交
59
    * [AliPay](#alipay)
F
fatedier 已提交
60
    * [Wechat Pay](#wechat-pay)
F
fatedier 已提交
61
    * [Paypal](#paypal)
F
fatedier 已提交
62

F
fatedier 已提交
63 64
<!-- vim-markdown-toc -->

F
fatedier 已提交
65 66
## Status

E
Eric Larssen 已提交
67
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 已提交
68

F
typo  
fatedier 已提交
69
**We may change any protocol and can't promise backward compatibility. Please check the release log when upgrading.**
F
fatedier 已提交
70

F
fatedier 已提交
71
## Architecture
F
fatedier 已提交
72

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

F
fatedier 已提交
75
## Example Usage
F
fatedier 已提交
76

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

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

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

F
fatedier 已提交
83
### Access your computer in LAN by SSH
F
fatedier 已提交
84

F
fatedier 已提交
85
1. Modify frps.ini:
F
fatedier 已提交
86 87 88 89 90 91 92 93 94 95 96

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

2. Start frps:

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

F
fatedier 已提交
97
3. Modify frpc.ini, `server_addr` is your frps's server IP:
F
fatedier 已提交
98 99 100 101 102 103 104 105

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

  [ssh]
F
fatedier 已提交
106 107
  type = tcp
  local_ip = 127.0.0.1
F
fatedier 已提交
108
  local_port = 22
F
fatedier 已提交
109
  remote_port = 6000
F
fatedier 已提交
110 111 112 113 114 115 116 117 118 119
  ```

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

F
fatedier 已提交
122
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 已提交
123

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

F
fatedier 已提交
126
1. Modify frps.ini, configure http port 8080:
F
fatedier 已提交
127 128 129 130 131 132 133 134 135 136 137 138

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

2. Start frps:

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

F
fatedier 已提交
139
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 已提交
140 141 142 143 144 145 146 147 148 149

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

  [web]
  type = http
  local_port = 80
F
fatedier 已提交
150
  custom_domains = www.yourdomain.com
F
fatedier 已提交
151 152 153 154 155 156
  ```

4. Start frpc:

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

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

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

F
fatedier 已提交
161 162
### Forward DNS query request

F
fatedier 已提交
163
1. Modify frps.ini:
F
fatedier 已提交
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186

  ```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 已提交
187
  remote_port = 6000
F
fatedier 已提交
188 189 190 191 192 193 194 195
  ```

4. Start frpc:

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

5. Send dns query request by dig:

H
Hyduan 已提交
196
  `dig @x.x.x.x -p 6000 www.google.com`
F
fatedier 已提交
197

F
fatedier 已提交
198 199 200 201
### Forward unix domain socket

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

F
fatedier 已提交
202 203 204
Configure frps same as above.

1. Start frpc with configurations:
F
fatedier 已提交
205 206

  ```ini
F
fatedier 已提交
207
  # frpc.ini
F
fatedier 已提交
208
  [common]
F
fatedier 已提交
209 210 211 212 213 214 215 216
  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
F
fatedier 已提交
217 218
  ```

F
fatedier 已提交
219
2. Get docker version by curl command:
F
fatedier 已提交
220

F
fatedier 已提交
221 222
  `curl http://x.x.x.x:6000/version`

F
fatedier 已提交
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248
### Expose a simple http file server

A simple way to visit files in the LAN.

Configure frps same as above.

1. Start frpc with configurations:

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

  [test_static_file]
  type = tcp
  remote_port = 6000
  plugin = static_file
  plugin_local_path = /tmp/file
  plugin_strip_prefix = static
  plugin_http_user = abc
  plugin_http_passwd = abc
  ```

2. Visit `http://x.x.x.x:6000/static/` by your browser, set correct user and password, so you can see files in `/tmp/file`.

F
fatedier 已提交
249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
### Enable HTTPS for local HTTP service

1. Start frpc with configurations:

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

  [test_htts2http]
  type = https
  custom_domains = test.yourdomain.com

  plugin = https2http
  plugin_local_addr = 127.0.0.1:80
  plugin_crt_path = ./server.crt
  plugin_key_path = ./server.key
  plugin_host_header_rewrite = 127.0.0.1
Z
zhouwenfeng 已提交
268
  plugin_header_X-From-Where = frp
F
fatedier 已提交
269 270 271 272
  ```

2. Visit `https://test.yourdomain.com`.

F
fatedier 已提交
273 274 275 276
### Expose your service in security

For some services, if expose them to the public network directly will be a security risk.

F
fatedier 已提交
277
**stcp(secret tcp)** helps you create a proxy avoiding any one can access it.
F
fatedier 已提交
278 279

Configure frps same as above.
F
fatedier 已提交
280

F
fatedier 已提交
281
1. Start frpc, forward ssh port and `remote_port` is useless:
F
fatedier 已提交
282 283 284 285 286 287 288

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

F
fatedier 已提交
289 290 291 292 293
  [secret_ssh]
  type = stcp
  sk = abcdefg
  local_ip = 127.0.0.1
  local_port = 22
F
fatedier 已提交
294 295
  ```

F
fatedier 已提交
296
2. Start another frpc in which you want to connect this ssh server:
F
fatedier 已提交
297

F
fatedier 已提交
298 299 300 301 302 303
  ```ini
  # frpc.ini
  [common]
  server_addr = x.x.x.x
  server_port = 7000

F
fatedier 已提交
304
  [secret_ssh_visitor]
F
fatedier 已提交
305
  type = stcp
F
fatedier 已提交
306
  role = visitor
F
fatedier 已提交
307 308 309 310 311
  server_name = secret_ssh
  sk = abcdefg
  bind_addr = 127.0.0.1
  bind_port = 6000
  ```
F
fatedier 已提交
312

F
fatedier 已提交
313
3. Connect to server in LAN by ssh assuming that username is test:
F
fatedier 已提交
314

F
fatedier 已提交
315
  `ssh -oPort=6000 test@127.0.0.1`
F
fatedier 已提交
316

F
fatedier 已提交
317 318 319 320 321 322 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 352 353 354 355 356 357 358 359 360 361 362 363 364
### P2P Mode

**xtcp** is designed for transmitting a large amount of data directly between two client.

Now it can't penetrate all types of NAT devices. You can try **stcp** if **xtcp** doesn't work.

1. Configure a udp port for xtcp:

  ```ini
  bind_udp_port = 7001
  ```

2. Start frpc, forward ssh port and `remote_port` is useless:

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

  [p2p_ssh]
  type = xtcp
  sk = abcdefg
  local_ip = 127.0.0.1
  local_port = 22
  ```

3. Start another frpc in which you want to connect this ssh server:

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

  [p2p_ssh_visitor]
  type = xtcp
  role = visitor
  server_name = p2p_ssh
  sk = abcdefg
  bind_addr = 127.0.0.1
  bind_port = 6000
  ```

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

  `ssh -oPort=6000 test@127.0.0.1`

F
fatedier 已提交
365
## Features
F
fatedier 已提交
366

F
fatedier 已提交
367
### Configuration File
F
fatedier 已提交
368

F
fatedier 已提交
369 370 371 372 373
You can find features which this document not metioned from full example configuration files.

[frps full configuration file](./conf/frps_full.ini)

[frpc full configuration file](./conf/frpc_full.ini)
F
fatedier 已提交
374

F
fatedier 已提交
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
### Configuration file template

Configuration file tempalte can be rendered using os environments. Template uses Go's standard format.

```ini
# frpc.ini
[common]
server_addr = {{ .Envs.FRP_SERVER_ADDR }}
server_port = 7000

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = {{ .Envs.FRP_SSH_REMOTE_PORT }}
```

Start frpc program:

```
export FRP_SERVER_ADDR="x.x.x.x"
export FRP_SSH_REMOTE_PORT="6000"
./frpc -c ./frpc.ini
```

frpc will auto render configuration file template using os environments.
All environments has prefix `.Envs`.

F
fatedier 已提交
403 404 405 406 407 408 409 410 411
### 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 已提交
412
# dashboard's username and password are both optional,if not set, default is admin.
F
fatedier 已提交
413 414
dashboard_user = admin
dashboard_pwd = admin
F
fatedier 已提交
415 416
```

E
Eric Larssen 已提交
417
Then visit `http://[server_addr]:7500` to see dashboard, default username and password are both `admin`.
F
fatedier 已提交
418 419 420

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

F
fatedier 已提交
421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436
### Admin UI

Admin UI help you check and manage frpc's configure.

Configure a address for admin UI to enable this feature:

```ini
[common]
admin_addr = 127.0.0.1
admin_port = 7400
admin_user = admin
admin_pwd = admin
```

Then visit `http://127.0.0.1:7400` to see admin UI, default username and password are both `admin`.

F
fatedier 已提交
437 438
### Authentication

F
fatedier 已提交
439
`token` in frps.ini and frpc.ini should be same.
F
fatedier 已提交
440 441 442

### Encryption and Compression

F
fatedier 已提交
443
Defalut value is false, you could decide if the proxy will use encryption or compression:
F
fatedier 已提交
444 445 446 447 448

```ini
# frpc.ini
[ssh]
type = tcp
F
fatedier 已提交
449 450
local_port = 22
remote_port = 6000
F
fatedier 已提交
451
use_encryption = true
F
fatedier 已提交
452
use_compression = true
F
fatedier 已提交
453 454
```

F
fatedier 已提交
455 456 457 458 459 460 461 462
#### TLS

frp support TLS protocol between frpc and frps since v0.25.0.

Config `tls_enable = true` in `common` section to frpc.ini to enable this feature.

For port multiplexing, frp send a first byte 0x17 to dial a TLS connection.

F
fatedier 已提交
463 464 465 466 467 468 469 470 471 472 473
### Hot-Reload frpc configuration

First you need to set admin port in frpc's configure file to let it provide HTTP API for more features.

```ini
# frpc.ini
[common]
admin_addr = 127.0.0.1
admin_port = 7400
```

F
fatedier 已提交
474
Then run command `frpc reload -c ./frpc.ini` and wait for about 10 seconds to let frpc create or update or delete proxies.
F
fatedier 已提交
475

F
fatedier 已提交
476
**Note that parameters in [common] section won't be modified except 'start' now.**
F
fatedier 已提交
477

F
fatedier 已提交
478 479 480 481
### Get proxy status from client

Use `frpc status -c ./frpc.ini` to get status of all proxies. You need to set admin port in frpc's configure file.

F
fatedier 已提交
482
### Port White List
F
fatedier 已提交
483

F
fatedier 已提交
484
`allow_ports` in frps.ini is used for preventing abuse of ports:
F
fatedier 已提交
485 486 487 488

```ini
# frps.ini
[common]
F
fatedier 已提交
489
allow_ports = 2000-3000,3001,3003,4000-50000
F
fatedier 已提交
490 491
```

F
fatedier 已提交
492
`allow_ports` consists of a specific port or a range of ports divided by `,`.
F
fatedier 已提交
493

F
fatedier 已提交
494 495
### Port Reuse

F
fatedier 已提交
496
Now `vhost_http_port` and `vhost_https_port` in frps can use same port with `bind_port`. frps will detect connection's protocol and handle it correspondingly.
F
fatedier 已提交
497 498 499

We would like to try to allow multiple proxies bind a same remote port with different protocols in the future.

F
fatedier 已提交
500 501 502 503 504 505 506 507 508 509 510 511
### 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 已提交
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538
### Support KCP Protocol

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 已提交
539 540 541 542 543 544 545 546
### 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 已提交
547
  ```ini
F
fatedier 已提交
548 549
  # frps.ini
  [common]
F
fatedier 已提交
550
  max_pool_count = 5
F
fatedier 已提交
551 552 553 554
  ```

2. Enable and specify the number of connection pool:

E
Eric Larssen 已提交
555
  ```ini
F
fatedier 已提交
556
  # frpc.ini
F
fatedier 已提交
557 558
  [common]
  pool_count = 1
F
fatedier 已提交
559 560
  ```

F
fatedier 已提交
561 562 563
### Load balancing

Load balancing is supported by `group`.
F
fatedier 已提交
564 565

This feature is available only for type `tcp` and `http` now.
F
fatedier 已提交
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587

```ini
# frpc.ini
[test1]
type = tcp
local_port = 8080
remote_port = 80
group = web
group_key = 123

[test2]
type = tcp
local_port = 8081
remote_port = 80
group = web
group_key = 123
```

`group_key` is used for authentication.

Proxies in same group will accept connections from port 80 randomly.

F
fatedier 已提交
588 589 590 591
For `tcp` type, `remote_port` in one group shoud be same.

For `http` type, `custom_domains, subdomain, locations` shoud be same.

F
fatedier 已提交
592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
### Health Check

Health check feature can help you achieve high availability with load balancing.

Add `health_check_type = {type}` to enable health check.

**type** can be tcp or http.

Type tcp will dial the service port and type http will send a http rquest to service and require a 200 response.

Type tcp configuration:

```ini
# frpc.ini
[test1]
type = tcp
local_port = 22
remote_port = 6000
# enable tcp health check
health_check_type = tcp
# dial timeout seconds
health_check_timeout_s = 3
# if continuous failed in 3 times, the proxy will be removed from frps
health_check_max_failed = 3
# every 10 seconds will do a health check
health_check_interval_s = 10
```

Type http configuration:
```ini
# frpc.ini
[web]
type = http
local_ip = 127.0.0.1
local_port = 80
custom_domains = test.yourdomain.com
# enable http health check
health_check_type = http
# frpc will send a GET http request '/status' to local http service
# http service is alive when it return 2xx http response code
health_check_url = /status
health_check_interval_s = 10
health_check_max_failed = 3
health_check_timeout_s = 3
```

F
fatedier 已提交
638 639
### Rewriting the Host Header

F
fatedier 已提交
640
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 已提交
641

F
fatedier 已提交
642 643
```ini
# frpc.ini
E
Eric Larssen 已提交
644
[web]
F
fatedier 已提交
645 646 647 648 649 650
type = http
local_port = 80
custom_domains = test.yourdomain.com
host_header_rewrite = dev.yourdomain.com
```

651
The `Host` request header will be rewritten to `Host: dev.yourdomain.com` before it reach your local http server.
F
fatedier 已提交
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668

### Set Headers In HTTP Request

You can set headers for proxy which type is `http`.

```ini
# frpc.ini
[web]
type = http
local_port = 80
custom_domains = test.yourdomain.com
host_header_rewrite = dev.yourdomain.com
header_X-From-Where = frp
```

Note that params which have prefix `header_` will be added to http request headers.
In this example, it will set header `X-From-Where: frp` to http request.
F
fatedier 已提交
669

F
fatedier 已提交
670 671
### Get Real IP

F
fatedier 已提交
672 673
#### HTTP X-Forwarded-For

F
fatedier 已提交
674 675
Features for http proxy only.

F
fatedier 已提交
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697
You can get user's real IP from HTTP request header `X-Forwarded-For` and `X-Real-IP`.

#### Proxy Protocol

frp support Proxy Protocol to send user's real IP to local service. It support all types without UDP.

Here is an example for https service:

```ini
# frpc.ini
[web]
type = https
local_port = 443
custom_domains = test.yourdomain.com

# now v1 and v2 is supported
proxy_protocol_version = v2
```

You can enable Proxy Protocol support in nginx to parse user's real IP to http header `X-Real-IP`.

Then you can get it from HTTP request header in your local service.
F
fatedier 已提交
698

F
fatedier 已提交
699 700 701 702 703 704
### 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 已提交
705
It can only be enabled when proxy type is http.
F
fatedier 已提交
706 707 708 709 710 711 712 713

```ini
# frpc.ini
[web]
type = http
local_port = 80
custom_domains = test.yourdomain.com
http_user = abc
714
http_pwd = abc
F
fatedier 已提交
715 716
```

F
fatedier 已提交
717
Visit `http://test.yourdomain.com` and now you need to input username and password.
F
fatedier 已提交
718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741

### 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 已提交
742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
### 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 已提交
764 765 766 767
### 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 已提交
768 769
It only works when protocol is tcp.

F
fatedier 已提交
770 771
```ini
# frpc.ini
F
fatedier 已提交
772
[common]
F
fatedier 已提交
773 774 775 776 777
server_addr = x.x.x.x
server_port = 7000
http_proxy = http://user:pwd@192.168.1.128:8080
```

F
fatedier 已提交
778 779 780 781 782 783 784 785 786 787 788 789 790
### Range ports mapping

Proxy name has prefix `range:` will support mapping range ports.

```ini
# frpc.ini
[range:test_tcp]
type = tcp
local_ip = 127.0.0.1
local_port = 6000-6006,6007
remote_port = 6000-6006,6007
```

F
fatedier 已提交
791
frpc will generate 8 proxies like `test_tcp_0, test_tcp_1 ... test_tcp_7`.
F
fatedier 已提交
792

F
fatedier 已提交
793 794 795 796
### Plugin

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

F
fatedier 已提交
797
Plugin is used for providing rich features. There are built-in plugins such as `unix_domain_socket`, `http_proxy`, `socks5`, `static_file` and you can see [example usage](#example-usage).
F
fatedier 已提交
798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814

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 已提交
815 816
## Development Plan

F
fatedier 已提交
817
* Log http request information in frps.
F
fatedier 已提交
818

819 820
## Contributing

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

F
fatedier 已提交
823 824 825
* 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.
L
Lukaz 已提交
826
* If you have some wonderful ideas, send email to fatedier@gmail.com.
F
fatedier 已提交
827

F
fatedier 已提交
828 829
**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 已提交
830 831 832 833
## Donation

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

F
fatedier 已提交
834 835
frp QQ group: 606194980

F
fatedier 已提交
836 837 838 839
### AliPay

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

F
fatedier 已提交
840 841 842 843
### Wechat Pay

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

F
fatedier 已提交
844 845 846
### Paypal

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