2015-12-21 23:25:54 +08:00
# frp
2016-02-03 18:40:46 +08:00
2020-12-03 20:41:37 +08:00
[![Build Status ](https://circleci.com/gh/fatedier/frp.svg?style=shield )](https://circleci.com/gh/fatedier/frp)
2020-05-24 14:05:31 +08:00
[![GitHub release ](https://img.shields.io/github/tag/fatedier/frp.svg?label=release )](https://github.com/fatedier/frp/releases)
2016-02-03 18:40:46 +08:00
2016-04-06 11:43:50 +08:00
[README ](README.md ) | [中文文档 ](README_zh.md )
2022-01-28 15:29:43 +08:00
< h3 align = "center" > Gold Sponsors< / h3 >
<!-- gold sponsors start -->
< p align = "center" >
< a href = "https://workos.com/?utm_campaign=github_repo&utm_medium=referral&utm_content=frp&utm_source=github" target = "_blank" >
2023-02-23 13:22:05 +08:00
< img width = "350px" src = "https://raw.githubusercontent.com/fatedier/frp/dev/doc/pic/sponsor_workos.png" >
< / a >
2022-01-28 15:29:43 +08:00
< / p >
<!-- gold sponsors end -->
## What is frp?
2023-02-26 02:54:53 +08:00
frp is a fast reverse proxy that allows you to expose a local server located behind a NAT or firewall to the Internet. It currently supports **TCP** and **UDP** , as well as **HTTP** and **HTTPS** protocols, enabling requests to be forwarded to internal services via domain name.
2022-01-28 15:29:43 +08:00
2023-02-26 02:54:53 +08:00
frp also offers a P2P connect mode.
2022-01-28 15:29:43 +08:00
2016-12-25 14:21:29 +08:00
## Table of Contents
2016-07-11 23:31:35 +08:00
2016-12-21 01:18:12 +08:00
<!-- vim - markdown - toc GFM -->
2017-12-05 01:34:33 +08:00
2019-10-14 05:46:08 +08:00
* [Development Status ](#development-status )
2023-07-02 00:35:33 +08:00
* [About V2 ](#about-v2 )
2016-07-11 23:35:34 +08:00
* [Architecture ](#architecture )
2016-08-13 22:32:11 +08:00
* [Example Usage ](#example-usage )
2023-02-27 14:44:16 +08:00
* [Access your computer in a LAN network via SSH ](#access-your-computer-in-a-lan-network-via-ssh )
2023-07-02 00:35:33 +08:00
* [Multiple SSH services sharing the same port ](#multiple-ssh-services-sharing-the-same-port )
2023-02-27 14:44:16 +08:00
* [Accessing Internal Web Services with Custom Domains in LAN ](#accessing-internal-web-services-with-custom-domains-in-lan )
* [Forward DNS query requests ](#forward-dns-query-requests )
* [Forward Unix Domain Socket ](#forward-unix-domain-socket )
2019-10-14 05:46:08 +08:00
* [Expose a simple HTTP file server ](#expose-a-simple-http-file-server )
2023-02-27 14:44:16 +08:00
* [Enable HTTPS for a local HTTP(S) service ](#enable-https-for-a-local-https-service )
2019-10-14 05:46:08 +08:00
* [Expose your service privately ](#expose-your-service-privately )
2017-12-05 01:34:33 +08:00
* [P2P Mode ](#p2p-mode )
2016-07-11 23:35:34 +08:00
* [Features ](#features )
2019-10-14 05:46:08 +08:00
* [Configuration Files ](#configuration-files )
* [Using Environment Variables ](#using-environment-variables )
2021-06-03 00:07:51 +08:00
* [Split Configures Into Different Files ](#split-configures-into-different-files )
2023-10-10 16:48:13 +08:00
* [Server Dashboard ](#server-dashboard )
2019-03-11 16:24:54 +08:00
* [Admin UI ](#admin-ui )
2020-03-11 14:13:16 +08:00
* [Monitor ](#monitor )
* [Prometheus ](#prometheus )
2019-10-14 05:46:08 +08:00
* [Authenticating the Client ](#authenticating-the-client )
2020-03-11 14:13:16 +08:00
* [Token Authentication ](#token-authentication )
* [OIDC Authentication ](#oidc-authentication )
2016-12-21 01:18:12 +08:00
* [Encryption and Compression ](#encryption-and-compression )
2019-03-11 16:24:54 +08:00
* [TLS ](#tls )
2019-10-14 05:46:08 +08:00
* [Hot-Reloading frpc configuration ](#hot-reloading-frpc-configuration )
2018-01-18 16:43:03 +08:00
* [Get proxy status from client ](#get-proxy-status-from-client )
2019-10-14 05:46:08 +08:00
* [Only allowing certain ports on the server ](#only-allowing-certain-ports-on-the-server )
2018-05-07 16:46:04 +08:00
* [Port Reuse ](#port-reuse )
2019-11-26 10:23:37 +08:00
* [Bandwidth Limit ](#bandwidth-limit )
* [For Each Proxy ](#for-each-proxy )
2017-05-18 19:08:43 +08:00
* [TCP Stream Multiplexing ](#tcp-stream-multiplexing )
2017-06-14 01:23:34 +08:00
* [Support KCP Protocol ](#support-kcp-protocol )
2022-12-18 18:43:42 +08:00
* [Support QUIC Protocol ](#support-quic-protocol )
2019-10-14 05:46:08 +08:00
* [Connection Pooling ](#connection-pooling )
2018-05-25 01:25:36 +08:00
* [Load balancing ](#load-balancing )
2019-10-14 05:46:08 +08:00
* [Service Health Check ](#service-health-check )
* [Rewriting the HTTP Host Header ](#rewriting-the-http-host-header )
* [Setting other HTTP Headers ](#setting-other-http-headers )
2017-07-17 00:57:10 +08:00
* [Get Real IP ](#get-real-ip )
2019-04-10 13:39:26 +08:00
* [HTTP X-Forwarded-For ](#http-x-forwarded-for )
* [Proxy Protocol ](#proxy-protocol )
2020-03-11 14:13:16 +08:00
* [Require HTTP Basic Auth (Password) for Web Services ](#require-http-basic-auth-password-for-web-services )
* [Custom Subdomain Names ](#custom-subdomain-names )
* [URL Routing ](#url-routing )
* [TCP Port Multiplexing ](#tcp-port-multiplexing )
2019-10-14 05:46:08 +08:00
* [Connecting to frps via HTTP PROXY ](#connecting-to-frps-via-http-proxy )
2020-01-03 11:35:12 +08:00
* [Client Plugins ](#client-plugins )
* [Server Manage Plugins ](#server-manage-plugins )
2016-07-11 23:35:34 +08:00
* [Contributing ](#contributing )
2016-08-24 13:36:38 +08:00
* [Donation ](#donation )
2022-01-26 20:56:00 +08:00
* [GitHub Sponsors ](#github-sponsors )
2021-01-27 13:07:44 +08:00
* [PayPal ](#paypal )
2016-03-14 15:26:26 +08:00
2016-12-21 01:18:12 +08:00
<!-- vim - markdown - toc -->
2019-10-14 05:46:08 +08:00
## Development Status
2016-03-14 15:26:26 +08:00
2023-02-26 02:54:53 +08:00
frp is currently under development. You can try the latest release version in the `master` branch, or use the `dev` branch to access the version currently in development.
2016-04-06 11:43:50 +08:00
2023-02-26 02:54:53 +08:00
We are currently working on version 2 and attempting to perform some code refactoring and improvements. However, please note that it will not be compatible with version 1.
2021-11-09 14:18:40 +08:00
2023-02-26 02:54:53 +08:00
We will transition from version 0 to version 1 at the appropriate time and will only accept bug fixes and improvements, rather than big feature requests.
2016-03-14 15:26:26 +08:00
2023-07-02 00:35:33 +08:00
### About V2
The complexity and difficulty of the v2 version are much higher than anticipated. I can only work on its development during fragmented time periods, and the constant interruptions disrupt productivity significantly. Given this situation, we will continue to optimize and iterate on the current version until we have more free time to proceed with the major version overhaul.
The concept behind v2 is based on my years of experience and reflection in the cloud-native domain, particularly in K8s and ServiceMesh. Its core is a modernized four-layer and seven-layer proxy, similar to envoy. This proxy itself is highly scalable, not only capable of implementing the functionality of intranet penetration but also applicable to various other domains. Building upon this highly scalable core, we aim to implement all the capabilities of frp v1 while also addressing the functionalities that were previously unachievable or difficult to implement in an elegant manner. Furthermore, we will maintain efficient development and iteration capabilities.
In addition, I envision frp itself becoming a highly extensible system and platform, similar to how we can provide a range of extension capabilities based on K8s. In K8s, we can customize development according to enterprise needs, utilizing features such as CRD, controller mode, webhook, CSI, and CNI. In frp v1, we introduced the concept of server plugins, which implemented some basic extensibility. However, it relies on a simple HTTP protocol and requires users to start independent processes and manage them on their own. This approach is far from flexible and convenient, and real-world demands vary greatly. It is unrealistic to expect a non-profit open-source project maintained by a few individuals to meet everyone's needs.
Finally, we acknowledge that the current design of modules such as configuration management, permission verification, certificate management, and API management is not modern enough. While we may carry out some optimizations in the v1 version, ensuring compatibility remains a challenging issue that requires a considerable amount of effort to address.
We sincerely appreciate your support for frp.
2016-07-11 23:31:35 +08:00
## Architecture
2016-03-14 15:26:26 +08:00
2016-07-11 23:31:35 +08:00
![architecture ](/doc/pic/architecture.png )
2016-03-14 15:26:26 +08:00
2016-07-11 23:31:35 +08:00
## Example Usage
2016-03-14 15:26:26 +08:00
2023-02-27 14:44:16 +08:00
To begin, download the latest program for your operating system and architecture from the [Release ](https://github.com/fatedier/frp/releases ) page.
2016-03-14 15:26:26 +08:00
2023-10-10 16:48:13 +08:00
Next, place the `frps` binary and server configuration file on Server A, which has a public IP address.
2016-03-14 15:26:26 +08:00
2023-10-10 16:48:13 +08:00
Finally, place the `frpc` binary and client configuration file on Server B, which is located on a LAN that cannot be directly accessed from the public internet.
2016-07-11 23:31:35 +08:00
2023-10-09 15:05:03 +08:00
Some antiviruses improperly mark frpc as malware and delete it. This is due to frp being a networking tool capable of creating reverse proxies. Antiviruses sometimes flag reverse proxies due to their ability to bypass firewall port restrictions. If you are using antivirus, then you may need to whitelist/exclude frpc in your antivirus settings to avoid accidental quarantine/deletion. See [issue 3637 ](https://github.com/fatedier/frp/issues/3637 ) for more details.
2023-02-27 14:44:16 +08:00
### Access your computer in a LAN network via SSH
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
1. Modify `frps.toml` on server A by setting the `bindPort` for frp clients to connect to:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
bindPort = 7000
2016-07-11 23:31:35 +08:00
```
2019-10-14 05:46:08 +08:00
2. Start `frps` on server A:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
`./frps -c ./frps.toml`
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
3. Modify `frpc.toml` on server B and set the `serverAddr` field to the public IP address of your frps server:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000
2016-07-11 23:31:35 +08:00
```
2023-10-10 16:48:13 +08:00
Note that the `localPort` (listened on the client) and `remotePort` (exposed on the server) are used for traffic going in and out of the frp system, while the `serverPort` is used for communication between frps and frpc.
2020-03-26 17:41:18 +08:00
2019-10-14 05:46:08 +08:00
4. Start `frpc` on server B:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
`./frpc -c ./frpc.toml`
2016-07-11 23:31:35 +08:00
2023-02-27 14:44:16 +08:00
5. To access server B from another machine through server A via SSH (assuming the username is `test` ), use the following command:
2016-07-11 23:31:35 +08:00
`ssh -oPort=6000 test@x.x.x.x`
2023-07-02 00:35:33 +08:00
### Multiple SSH services sharing the same port
This example implements multiple SSH services exposed through the same port using a proxy of type tcpmux. Similarly, as long as the client supports the HTTP Connect proxy connection method, port reuse can be achieved in this way.
2023-10-10 16:48:13 +08:00
1. Deploy frps on a machine with a public IP and modify the frps.toml file. Here is a simplified configuration:
2023-07-02 00:35:33 +08:00
2023-10-10 16:48:13 +08:00
```toml
bindPort = 7000
tcpmuxHTTPConnectPort = 5002
2023-07-02 00:35:33 +08:00
```
2. Deploy frpc on the internal machine A with the following configuration:
2023-10-10 16:48:13 +08:00
```toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "ssh1"
type = "tcpmux"
multiplexer = "httpconnect"
customDomains = ["machine-a.example.com"]
localIP = "127.0.0.1"
localPort = 22
2023-07-02 00:35:33 +08:00
```
3. Deploy another frpc on the internal machine B with the following configuration:
2023-10-10 16:48:13 +08:00
```toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "ssh2"
type = "tcpmux"
multiplexer = "httpconnect"
customDomains = ["machine-b.example.com"]
localIP = "127.0.0.1"
localPort = 22
2023-07-02 00:35:33 +08:00
```
4. To access internal machine A using SSH ProxyCommand, assuming the username is "test":
`ssh -o 'proxycommand socat - PROXY:x.x.x.x:machine-a.example.com:22,proxyport=5002' test@machine-a`
5. To access internal machine B, the only difference is the domain name, assuming the username is "test":
`ssh -o 'proxycommand socat - PROXY:x.x.x.x:machine-b.example.com:22,proxyport=5002' test@machine-b`
2023-02-27 14:44:16 +08:00
### Accessing Internal Web Services with Custom Domains in LAN
2016-07-11 23:31:35 +08:00
2023-02-27 14:44:16 +08:00
Sometimes we need to expose a local web service behind a NAT network to others for testing purposes with our own domain name.
2016-07-11 23:31:35 +08:00
2023-02-27 14:44:16 +08:00
Unfortunately, we cannot resolve a domain name to a local IP. However, we can use frp to expose an HTTP(S) service.
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
1. Modify `frps.toml` and set the HTTP port for vhost to 8080:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
bindPort = 7000
vhostHTTPPort = 8080
2016-07-11 23:31:35 +08:00
```
2023-10-16 11:29:51 +08:00
If you want to configure an https proxy, you need to set up the `vhostHTTPSPort` .
2023-07-02 00:35:33 +08:00
2019-10-14 05:46:08 +08:00
2. Start `frps` :
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
`./frps -c ./frps.toml`
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
3. Modify `frpc.toml` and set `serverAddr` to the IP address of the remote frps server. Specify the `localPort` of your web service:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["www.example.com"]
2016-07-11 23:31:35 +08:00
```
2019-10-14 05:46:08 +08:00
4. Start `frpc` :
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
`./frpc -c ./frpc.toml`
2016-07-11 23:31:35 +08:00
2023-02-27 14:44:16 +08:00
5. Map the A record of `www.example.com` to either the public IP of the remote frps server or a CNAME record pointing to your original domain.
2016-07-11 23:31:35 +08:00
2023-02-27 14:44:16 +08:00
6. Visit your local web service using url `http://www.example.com:8080` .
2016-07-11 23:31:35 +08:00
2023-02-27 14:44:16 +08:00
### Forward DNS query requests
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
1. Modify `frps.toml` :
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
bindPort = 7000
2016-12-21 01:18:12 +08:00
```
2019-10-14 05:46:08 +08:00
2. Start `frps` :
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
`./frps -c ./frps.toml`
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
3. Modify `frpc.toml` and set `serverAddr` to the IP address of the remote frps server. Forward DNS query requests to the Google Public DNS server `8.8.8.8:53` :
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
[[proxies]]
name = "dns"
type = "udp"
localIP = "8.8.8.8"
localPort = 53
remotePort = 6000
2016-12-21 01:18:12 +08:00
```
4. Start frpc:
2023-10-10 16:48:13 +08:00
`./frpc -c ./frpc.toml`
2016-12-21 01:18:12 +08:00
2023-02-27 14:44:16 +08:00
5. Test DNS resolution using the `dig` command:
2016-12-21 01:18:12 +08:00
2017-09-26 21:06:28 +08:00
`dig @x.x.x.x -p 6000 www.google.com`
2016-12-21 01:18:12 +08:00
2023-02-27 14:44:16 +08:00
### Forward Unix Domain Socket
2017-06-12 01:31:33 +08:00
2019-10-14 05:46:08 +08:00
Expose a Unix domain socket (e.g. the Docker daemon socket) as TCP.
2017-06-12 01:31:33 +08:00
2023-02-27 14:44:16 +08:00
Configure `frps` as above.
2017-07-17 00:57:10 +08:00
2023-02-27 14:44:16 +08:00
1. Start `frpc` with the following configuration:
2017-06-12 01:31:33 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "unix_domain_socket"
type = "tcp"
remotePort = 6000
[proxies.plugin]
type = "unix_domain_socket"
unixPath = "/var/run/docker.sock"
2017-06-12 01:31:33 +08:00
```
2023-02-27 14:44:16 +08:00
2. Test the configuration by getting the docker version using `curl` :
2017-06-12 01:31:33 +08:00
2017-07-17 00:57:10 +08:00
`curl http://x.x.x.x:6000/version`
2019-10-14 05:46:08 +08:00
### Expose a simple HTTP file server
2018-01-24 23:27:03 +08:00
2023-02-27 14:44:16 +08:00
Expose a simple HTTP file server to access files stored in the LAN from the public Internet.
2018-01-24 23:27:03 +08:00
2023-02-27 14:44:16 +08:00
Configure `frps` as described above, then:
2018-01-24 23:27:03 +08:00
2023-02-27 14:44:16 +08:00
1. Start `frpc` with the following configuration:
2018-01-24 23:27:03 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "test_static_file"
type = "tcp"
remotePort = 6000
[proxies.plugin]
type = "static_file"
localPath = "/tmp/files"
stripPrefix = "static"
httpUser = "abc"
httpPassword = "abc"
2018-01-24 23:27:03 +08:00
```
2023-02-27 14:44:16 +08:00
2. Visit `http://x.x.x.x:6000/static/` from your browser and specify correct username and password to view files in `/tmp/files` on the `frpc` machine.
2018-01-24 23:27:03 +08:00
2023-02-27 14:44:16 +08:00
### Enable HTTPS for a local HTTP(S) service
2021-01-27 13:14:16 +08:00
2023-10-16 11:29:51 +08:00
You may substitute `https2https` for the plugin, and point the `localAddr` to a HTTPS endpoint.
2019-04-10 13:39:26 +08:00
2023-02-27 14:44:16 +08:00
1. Start `frpc` with the following configuration:
2019-04-10 13:39:26 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
vhostHTTPSPort = 443
[[proxies]]
name = "test_https2http"
type = "https"
customDomains = ["test.example.com"]
[proxies.plugin]
type = "https2http"
localAddr = "127.0.0.1:80"
crtPath = "./server.crt"
keyPath = "./server.key"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"
2019-04-10 13:39:26 +08:00
```
2019-10-14 05:46:08 +08:00
2. Visit `https://test.example.com` .
2019-04-10 13:39:26 +08:00
2019-10-14 05:46:08 +08:00
### Expose your service privately
2017-07-17 00:57:10 +08:00
2023-02-27 14:44:16 +08:00
To mitigate risks associated with exposing certain services directly to the public network, STCP (Secret TCP) mode requires a preshared key to be used for access to the service from other clients.
2017-07-17 00:57:10 +08:00
2019-10-14 05:46:08 +08:00
Configure `frps` same as above.
2017-07-17 00:57:10 +08:00
2023-10-16 11:29:51 +08:00
1. Start `frpc` on machine B with the following config. This example is for exposing the SSH service (port 22), and note the `secretKey` field for the preshared key, and that the `remotePort` field is removed here:
2017-06-12 01:31:33 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "secret_ssh"
type = "stcp"
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
2017-06-12 01:31:33 +08:00
```
2023-10-12 19:57:59 +08:00
2. Start another `frpc` (typically on another machine C) with the following config to access the SSH service with a security key (`secretKey` field):
2017-06-12 01:31:33 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[visitors]]
name = "secret_ssh_visitor"
type = "stcp"
serverName = "secret_ssh"
secretKey = "abcdefg"
bindAddr = "127.0.0.1"
bindPort = 6000
2017-07-17 00:57:10 +08:00
```
2017-06-12 01:31:33 +08:00
2019-10-14 05:46:08 +08:00
3. On machine C, connect to SSH on machine B, using this command:
2017-06-12 01:31:33 +08:00
2019-10-14 05:46:08 +08:00
`ssh -oPort=6000 127.0.0.1`
2017-06-12 01:31:33 +08:00
2017-12-05 01:34:33 +08:00
### P2P Mode
2023-02-27 14:44:16 +08:00
**xtcp** is designed to transmit large amounts of data directly between clients. A frps server is still needed, as P2P here only refers to the actual data transmission.
2017-12-05 01:34:33 +08:00
2023-02-27 14:44:16 +08:00
Note that it may not work with all types of NAT devices. You might want to fallback to stcp if xtcp doesn't work.
2017-12-05 01:34:33 +08:00
2023-10-10 16:48:13 +08:00
1. Start `frpc` on machine B, and expose the SSH port. Note that the `remotePort` field is removed:
2017-12-05 01:34:33 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
2023-05-29 01:09:53 +08:00
# set up a new stun server if the default one is not available.
2023-10-10 16:48:13 +08:00
# natHoleStunServer = "xxx"
[[proxies]]
name = "p2p_ssh"
type = "xtcp"
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
2017-12-05 01:34:33 +08:00
```
2023-05-29 01:09:53 +08:00
2. Start another `frpc` (typically on another machine C) with the configuration to connect to SSH using P2P mode:
2017-12-05 01:34:33 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
2023-05-29 01:09:53 +08:00
# set up a new stun server if the default one is not available.
2023-10-10 16:48:13 +08:00
# natHoleStunServer = "xxx"
[[visitors]]
name = "p2p_ssh_visitor"
type = "xtcp"
serverName = "p2p_ssh"
secretKey = "abcdefg"
bindAddr = "127.0.0.1"
bindPort = 6000
2023-05-29 01:09:53 +08:00
# when automatic tunnel persistence is required, set it to true
2023-10-10 16:48:13 +08:00
keepTunnelOpen = false
2017-12-05 01:34:33 +08:00
```
2023-05-29 01:09:53 +08:00
3. On machine C, connect to SSH on machine B, using this command:
2017-12-05 01:34:33 +08:00
2019-10-14 05:46:08 +08:00
`ssh -oPort=6000 127.0.0.1`
2017-12-05 01:34:33 +08:00
2017-07-17 00:57:10 +08:00
## Features
2017-06-12 01:31:33 +08:00
2019-10-14 05:46:08 +08:00
### Configuration Files
2017-06-12 01:31:33 +08:00
2023-10-10 16:48:13 +08:00
Since v0.52.0, we support TOML, YAML, and JSON for configuration. Please note that INI is deprecated and will be removed in future releases. New features will only be available in TOML, YAML, or JSON. Users wanting these new features should switch their configuration format accordingly.
2019-10-14 05:46:08 +08:00
Read the full example configuration files to find out even more features not described here.
2017-07-17 00:57:10 +08:00
2023-10-10 16:48:13 +08:00
Examples use TOML format, but you can still use YAML or JSON.
2017-07-17 00:57:10 +08:00
2023-10-24 10:42:51 +08:00
These configuration files is for reference only. Please do not use this configuration directly to run the program as it may have various issues.
2023-10-10 16:48:13 +08:00
2023-10-24 10:42:51 +08:00
[Full configuration file for frps (Server) ](./conf/frps_full_example.toml )
[Full configuration file for frpc (Client) ](./conf/frpc_full_example.toml )
2016-07-11 23:31:35 +08:00
2019-10-14 05:46:08 +08:00
### Using Environment Variables
2018-12-11 11:56:00 +08:00
2019-10-14 05:46:08 +08:00
Environment variables can be referenced in the configuration file, using Go's standard format:
2018-12-11 11:56:00 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "{{ .Envs.FRP_SERVER_ADDR }}"
serverPort = 7000
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = "{{ .Envs.FRP_SSH_REMOTE_PORT }}"
2018-12-11 11:56:00 +08:00
```
2019-10-14 05:46:08 +08:00
With the config above, variables can be passed into `frpc` program like this:
2018-12-11 11:56:00 +08:00
```
2023-10-10 16:48:13 +08:00
export FRP_SERVER_ADDR=x.x.x.x
export FRP_SSH_REMOTE_PORT=6000
./frpc -c ./frpc.toml
2018-12-11 11:56:00 +08:00
```
2019-10-14 05:46:08 +08:00
`frpc` will render configuration file template using OS environment variables. Remember to prefix your reference with `.Envs` .
2018-12-11 11:56:00 +08:00
2021-06-03 00:07:51 +08:00
### Split Configures Into Different Files
You can split multiple proxy configs into different files and include them in the main file.
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
includes = ["./confd/*.toml"]
2021-06-03 00:07:51 +08:00
```
2023-10-10 16:48:13 +08:00
```toml
# ./confd/test.toml
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000
2021-06-03 00:07:51 +08:00
```
2023-10-10 16:48:13 +08:00
### Server Dashboard
2016-08-12 12:50:12 +08:00
2019-10-02 03:58:35 +08:00
Check frp's status and proxies' statistics information by Dashboard.
2016-08-12 12:50:12 +08:00
Configure a port for dashboard to enable this feature:
2023-10-10 16:48:13 +08:00
```toml
webServer.port = 7500
2021-05-10 23:04:26 +08:00
# dashboard's username and password are both optional
2023-10-10 16:48:13 +08:00
webServer.user = "admin"
webServer.password = "admin"
2016-08-12 12:50:12 +08:00
```
2023-10-16 11:29:51 +08:00
Then visit `http://[serverAddr]:7500` to see the dashboard, with username and password both being `admin` .
2016-08-12 12:50:12 +08:00
2022-06-27 10:08:02 +08:00
Additionally, you can use HTTPS port by using your domains wildcard or normal SSL certificate:
2023-10-10 16:48:13 +08:00
```toml
webServer.port = 7500
2022-06-27 10:08:02 +08:00
# dashboard's username and password are both optional
2023-10-10 16:48:13 +08:00
webServer.user = "admin"
webServer.password = "admin"
webServer.tls.certFile = "server.crt"
webServer.tls.keyFile = "server.key"
2022-06-27 10:08:02 +08:00
```
2023-10-16 11:29:51 +08:00
Then visit `https://[serverAddr]:7500` to see the dashboard in secure HTTPS connection, with username and password both being `admin` .
2022-06-27 10:08:02 +08:00
2016-08-12 12:50:12 +08:00
![dashboard ](/doc/pic/dashboard.png )
2023-10-10 16:48:13 +08:00
### Client Admin UI
2019-03-11 16:24:54 +08:00
2023-10-10 16:48:13 +08:00
The Client Admin UI helps you check and manage frpc's configuration.
2019-03-11 16:24:54 +08:00
2019-10-02 03:58:35 +08:00
Configure an address for admin UI to enable this feature:
2019-03-11 16:24:54 +08:00
2023-10-10 16:48:13 +08:00
```toml
webServer.addr = "127.0.0.1"
webServer.port = 7400
webServer.user = "admin"
webServer.password = "admin"
2019-03-11 16:24:54 +08:00
```
2021-05-10 23:04:26 +08:00
Then visit `http://127.0.0.1:7400` to see admin UI, with username and password both being `admin` .
2019-03-11 16:24:54 +08:00
2020-03-11 14:13:16 +08:00
### Monitor
2023-10-10 16:48:13 +08:00
When web server is enabled, frps will save monitor data in cache for 7 days. It will be cleared after process restart.
2020-03-11 14:13:16 +08:00
Prometheus is also supported.
#### Prometheus
2023-10-10 16:48:13 +08:00
Enable dashboard first, then configure `enablePrometheus = true` in `frps.toml` .
2020-03-11 14:13:16 +08:00
`http://{dashboard_addr}/metrics` will provide prometheus monitor data.
2019-10-14 05:46:08 +08:00
### Authenticating the Client
2016-07-11 23:31:35 +08:00
2020-03-01 10:57:01 +08:00
There are 2 authentication methods to authenticate frpc with frps.
2023-10-10 16:48:13 +08:00
You can decide which one to use by configuring `auth.method` in `frpc.toml` and `frps.toml` , the default one is token.
2020-03-01 10:57:01 +08:00
2023-10-10 16:48:13 +08:00
Configuring `auth.additionalScopes = ["HeartBeats"]` will use the configured authentication method to add and validate authentication on every heartbeat between frpc and frps.
2020-03-01 10:57:01 +08:00
2023-10-10 16:48:13 +08:00
Configuring `auth.additionalScopes = ["NewWorkConns"]` will do the same for every new work connection between frpc and frps.
2020-03-01 10:57:01 +08:00
#### Token Authentication
2023-10-10 16:48:13 +08:00
When specifying `auth.method = "token"` in `frpc.toml` and `frps.toml` - token based authentication will be used.
2020-03-01 10:57:01 +08:00
2023-10-10 16:48:13 +08:00
Make sure to specify the same `auth.token` in `frps.toml` and `frpc.toml` for frpc to pass frps validation
2020-03-01 10:57:01 +08:00
#### OIDC Authentication
2023-10-10 16:48:13 +08:00
When specifying `auth.method = "oidc"` in `frpc.toml` and `frps.toml` - OIDC based authentication will be used.
2020-03-01 10:57:01 +08:00
OIDC stands for OpenID Connect, and the flow used is called [Client Credentials Grant ](https://tools.ietf.org/html/rfc6749#section-4.4 ).
2023-10-10 16:48:13 +08:00
To use this authentication type - configure `frpc.toml` and `frps.toml` as follows:
2020-03-01 10:57:01 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
auth.method = "oidc"
auth.oidc.issuer = "https://example-oidc-issuer.com/"
auth.oidc.audience = "https://oidc-audience.com/.default"
2020-03-01 10:57:01 +08:00
```
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
auth.method = "oidc"
auth.oidc.clientID = "98692467-37de-409a-9fac-bb2585826f18" # Replace with OIDC client ID
auth.oidc.clientSecret = "oidc_secret"
auth.oidc.audience = "https://oidc-audience.com/.default"
auth.oidc.tokenEndpointURL = "https://example-oidc-endpoint.com/oauth2/v2.0/token"
2020-03-01 10:57:01 +08:00
```
2016-07-11 23:31:35 +08:00
### Encryption and Compression
2019-10-14 05:46:08 +08:00
The features are off by default. You can turn on encryption and/or compression:
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "ssh"
type = "tcp"
localPort = 22
remotePort = 6000
transport.useEncryption = true
transport.useCompression = true
2016-07-11 23:31:35 +08:00
```
2019-03-11 16:24:54 +08:00
#### TLS
2023-10-10 16:48:13 +08:00
Since v0.50.0, the default value of `transport.tls.enable` and `transport.tls.disableCustomTLSFirstByte` has been changed to true, and tls is enabled by default.
For port multiplexing, frp sends a first byte `0x17` to dial a TLS connection. This only takes effect when you set `transport.tls.disableCustomTLSFirstByte` to false.
2019-03-11 16:24:54 +08:00
2023-10-10 16:48:13 +08:00
To **enforce** `frps` to only accept TLS connections - configure `transport.tls.force = true` in `frps.toml` . **This is optional.**
2021-01-27 13:07:44 +08:00
2023-10-10 16:48:13 +08:00
**`frpc` TLS settings:**
2021-01-27 13:07:44 +08:00
2023-10-10 16:48:13 +08:00
```toml
transport.tls.enable = true
transport.tls.certFile = "certificate.crt"
transport.tls.keyFile = "certificate.key"
transport.tls.trustedCaFile = "ca.crt"
2021-01-27 13:07:44 +08:00
```
2023-10-10 16:48:13 +08:00
**`frps` TLS settings:**
```toml
transport.tls.force = true
transport.tls.certFile = "certificate.crt"
transport.tls.keyFile = "certificate.key"
transport.tls.trustedCaFile = "ca.crt"
2021-01-27 13:07:44 +08:00
```
You will need **a root CA cert** and **at least one SSL/TLS certificate** . It **can** be self-signed or regular (such as Let's Encrypt or another SSL/TLS certificate provider).
If you using `frp` via IP address and not hostname, make sure to set the appropriate IP address in the Subject Alternative Name (SAN) area when generating SSL/TLS Certificates.
2020-02-11 01:01:23 +08:00
2021-02-22 13:59:21 +08:00
Given an example:
* Prepare openssl config file. It exists at `/etc/pki/tls/openssl.cnf` in Linux System and `/System/Library/OpenSSL/openssl.cnf` in MacOS, and you can copy it to current path, like `cp /etc/pki/tls/openssl.cnf ./my-openssl.cnf` . If not, you can build it by yourself, like:
```
cat > my-openssl.cnf < < EOF
[ ca ]
default_ca = CA_default
[ CA_default ]
x509_extensions = usr_cert
[ req ]
default_bits = 2048
default_md = sha256
default_keyfile = privkey.pem
distinguished_name = req_distinguished_name
attributes = req_attributes
x509_extensions = v3_ca
string_mask = utf8only
[ req_distinguished_name ]
[ req_attributes ]
[ usr_cert ]
basicConstraints = CA:FALSE
nsComment = "OpenSSL Generated Certificate"
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid,issuer
[ v3_ca ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = CA:true
EOF
```
* build ca certificates:
```
openssl genrsa -out ca.key 2048
openssl req -x509 -new -nodes -key ca.key -subj "/CN=example.ca.com" -days 5000 -out ca.crt
```
* build frps certificates:
```
openssl genrsa -out server.key 2048
openssl req -new -sha256 -key server.key \
-subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=server.com" \
-reqexts SAN \
-config < (cat my-openssl.cnf < (printf "\n[SAN]\nsubjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com")) \
-out server.csr
2022-08-16 20:47:56 +08:00
openssl x509 -req -days 365 -sha256 \
2021-02-22 13:59:21 +08:00
-in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-extfile < (printf "subjectAltName=DNS:localhost,IP:127.0.0.1,DNS:example.server.com") \
-out server.crt
```
* build frpc certificates:
```
openssl genrsa -out client.key 2048
openssl req -new -sha256 -key client.key \
-subj "/C=XX/ST=DEFAULT/L=DEFAULT/O=DEFAULT/CN=client.com" \
-reqexts SAN \
-config < (cat my-openssl.cnf < (printf "\n[SAN]\nsubjectAltName=DNS:client.com,DNS:example.client.com")) \
-out client.csr
2022-08-16 20:47:56 +08:00
openssl x509 -req -days 365 -sha256 \
2021-02-22 13:59:21 +08:00
-in client.csr -CA ca.crt -CAkey ca.key -CAcreateserial \
-extfile < (printf "subjectAltName=DNS:client.com,DNS:example.client.com") \
-out client.crt
```
2019-10-14 05:46:08 +08:00
### Hot-Reloading frpc configuration
2017-07-17 00:57:10 +08:00
2023-10-10 16:48:13 +08:00
The `webServer` fields are required for enabling HTTP API:
2017-07-17 00:57:10 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
webServer.addr = "127.0.0.1"
webServer.port = 7400
2017-07-17 00:57:10 +08:00
```
2023-10-10 16:48:13 +08:00
Then run command `frpc reload -c ./frpc.toml` and wait for about 10 seconds to let `frpc` create or update or remove proxies.
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
**Note that global client parameters won't be modified except 'start'.**
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
You can run command `frpc verify -c ./frpc.toml` before reloading to check if there are config errors.
2021-06-03 00:07:51 +08:00
2018-01-18 16:43:03 +08:00
### Get proxy status from client
2023-10-10 16:48:13 +08:00
Use `frpc status -c ./frpc.toml` to get status of all proxies. The `webServer` fields are required for enabling HTTP API.
2018-01-18 16:43:03 +08:00
2019-10-14 05:46:08 +08:00
### Only allowing certain ports on the server
2016-07-11 23:31:35 +08:00
2023-10-10 16:48:13 +08:00
`allowPorts` in `frps.toml` is used to avoid abuse of ports:
2016-08-12 12:50:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
allowPorts = [
{ start = 2000, end = 3000 },
{ single = 3001 },
{ single = 3003 },
{ start = 4000, end = 50000 }
]
2016-08-12 12:50:12 +08:00
```
2018-05-07 16:46:04 +08:00
### Port Reuse
2023-10-10 16:48:13 +08:00
`vhostHTTPPort` and `vhostHTTPSPort` in frps can use same port with `bindPort` . frps will detect the connection's protocol and handle it correspondingly.
2018-05-07 16:46:04 +08:00
2023-10-11 11:49:40 +08:00
What you need to pay attention to is that if you want to configure `vhostHTTPSPort` and `bindPort` to the same port, you need to first set `transport.tls.disableCustomTLSFirstByte` to false.
2018-05-07 16:46:04 +08:00
We would like to try to allow multiple proxies bind a same remote port with different protocols in the future.
2019-11-26 10:23:37 +08:00
### Bandwidth Limit
#### For Each Proxy
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "ssh"
type = "tcp"
localPort = 22
remotePort = 6000
transport.bandwidthLimit = "1MB"
2019-11-26 10:23:37 +08:00
```
2023-10-10 16:48:13 +08:00
Set `transport.bandwidthLimit` in each proxy's configure to enable this feature. Supported units are `MB` and `KB` .
2019-11-26 10:23:37 +08:00
2023-10-10 16:48:13 +08:00
Set `transport.bandwidthLimitMode` to `client` or `server` to limit bandwidth on the client or server side. Default is `client` .
2023-02-09 00:38:36 +08:00
2017-05-18 19:08:43 +08:00
### TCP Stream Multiplexing
2019-10-14 05:46:08 +08:00
frp supports tcp stream multiplexing since v0.10.0 like HTTP2 Multiplexing, in which case all logic connections to the same frpc are multiplexed into the same TCP connection.
2017-05-18 19:08:43 +08:00
2023-10-10 16:48:13 +08:00
You can disable this feature by modify `frps.toml` and `frpc.toml` :
2017-05-18 19:08:43 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml and frpc.toml, must be same
tcpMux = false
2017-05-18 19:08:43 +08:00
```
2017-06-14 01:23:34 +08:00
### 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.
2019-10-14 05:46:08 +08:00
KCP mode uses UDP as the underlying transport. Using KCP in frp:
2017-06-14 01:23:34 +08:00
2019-10-14 05:46:08 +08:00
1. Enable KCP in frps:
2017-06-14 01:23:34 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
bindPort = 7000
2019-10-14 05:46:08 +08:00
# Specify a UDP port for KCP.
2023-10-10 16:48:13 +08:00
kcpBindPort = 7000
2017-06-14 01:23:34 +08:00
```
2023-10-10 16:48:13 +08:00
The `kcpBindPort` number can be the same number as `bindPort` , since `bindPort` field specifies a TCP port.
2019-10-14 05:46:08 +08:00
2023-10-10 16:48:13 +08:00
2. Configure `frpc.toml` to use KCP to connect to frps:
2017-06-14 01:23:34 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
# Same as the 'kcpBindPort' in frps.toml
serverPort = 7000
transport.protocol = "kcp"
2017-06-14 01:23:34 +08:00
```
2022-12-18 18:43:42 +08:00
### Support QUIC Protocol
QUIC is a new multiplexed transport built on top of UDP.
Using QUIC in frp:
1. Enable QUIC in frps:
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
bindPort = 7000
2022-12-18 18:43:42 +08:00
# Specify a UDP port for QUIC.
2023-10-10 16:48:13 +08:00
quicBindPort = 7000
2022-12-18 18:43:42 +08:00
```
2023-10-16 11:29:51 +08:00
The `quicBindPort` number can be the same number as `bindPort` , since `bindPort` field specifies a TCP port.
2022-12-18 18:43:42 +08:00
2023-10-10 16:48:13 +08:00
2. Configure `frpc.toml` to use QUIC to connect to frps:
2022-12-18 18:43:42 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
# Same as the 'quicBindPort' in frps.toml
serverPort = 7000
transport.protocol = "quic"
2022-12-18 18:43:42 +08:00
```
2019-10-14 05:46:08 +08:00
### Connection Pooling
2016-08-12 12:50:12 +08:00
2019-10-14 05:46:08 +08:00
By default, frps creates a new frpc connection to the backend service upon a user request. With connection pooling, frps keeps a certain number of pre-established connections, reducing the time needed to establish a connection.
2016-08-12 12:50:12 +08:00
2019-10-14 05:46:08 +08:00
This feature is suitable for a large number of short connections.
2016-08-12 12:50:12 +08:00
2023-10-10 16:48:13 +08:00
1. Configure the limit of pool count each proxy can use in `frps.toml` :
2016-08-12 12:50:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
transport.maxPoolCount = 5
2016-08-12 12:50:12 +08:00
```
2. Enable and specify the number of connection pool:
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
transport.poolCount = 1
2016-08-12 12:50:12 +08:00
```
2018-05-25 01:25:36 +08:00
### Load balancing
Load balancing is supported by `group` .
2019-07-31 00:41:43 +08:00
2021-03-19 16:06:22 +08:00
This feature is only available for types `tcp` , `http` , `tcpmux` now.
2018-05-25 01:25:36 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "test1"
type = "tcp"
localPort = 8080
remotePort = 80
loadBalancer.group = "web"
loadBalancer.groupKey = "123"
[[proxies]]
name = "test2"
type = "tcp"
localPort = 8081
remotePort = 80
loadBalancer.group = "web"
loadBalancer.groupKey = "123"
2018-05-25 01:25:36 +08:00
```
2023-10-10 16:48:13 +08:00
`loadBalancer.groupKey` is used for authentication.
2018-05-25 01:25:36 +08:00
2019-10-14 05:46:08 +08:00
Connections to port 80 will be dispatched to proxies in the same group randomly.
2018-05-25 01:25:36 +08:00
2023-10-10 16:48:13 +08:00
For type `tcp` , `remotePort` in the same group should be the same.
2019-07-31 00:41:43 +08:00
2023-10-10 16:48:13 +08:00
For type `http` , `customDomains` , `subdomain` , `locations` should be the same.
2019-07-31 00:41:43 +08:00
2019-10-14 05:46:08 +08:00
### Service Health Check
2019-01-15 11:27:53 +08:00
Health check feature can help you achieve high availability with load balancing.
2023-10-10 16:48:13 +08:00
Add `healthCheck.type = "tcp"` or `healthCheck.type = "http"` to enable health check.
2019-01-15 11:27:53 +08:00
2019-10-14 05:46:08 +08:00
With health check type **tcp** , the service port will be pinged (TCPing):
2019-01-15 11:27:53 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "test1"
type = "tcp"
localPort = 22
remotePort = 6000
2019-10-14 05:46:08 +08:00
# Enable TCP health check
2023-10-10 16:48:13 +08:00
healthCheck.type = "tcp"
2019-10-14 05:46:08 +08:00
# TCPing timeout seconds
2023-10-10 16:48:13 +08:00
healthCheck.timeoutSeconds = 3
2019-10-14 05:46:08 +08:00
# If health check failed 3 times in a row, the proxy will be removed from frps
2023-10-10 16:48:13 +08:00
healthCheck.maxFailed = 3
2019-10-14 05:46:08 +08:00
# A health check every 10 seconds
2023-10-10 16:48:13 +08:00
healthCheck.intervalSeconds = 10
2019-01-15 11:27:53 +08:00
```
2019-10-14 05:46:08 +08:00
With health check type **http** , an HTTP request will be sent to the service and an HTTP 2xx OK response is expected:
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web"
type = "http"
localIP = "127.0.0.1"
localPort = 80
customDomains = ["test.example.com"]
2019-10-14 05:46:08 +08:00
# Enable HTTP health check
2023-10-10 16:48:13 +08:00
healthCheck.type = "http"
2019-10-14 05:46:08 +08:00
# frpc will send a GET request to '/status'
# and expect an HTTP 2xx OK response
2023-10-10 16:48:13 +08:00
healthCheck.path = "/status"
healthCheck.timeoutSeconds = 3
healthCheck.maxFailed = 3
healthCheck.intervalSeconds = 10
2019-01-15 11:27:53 +08:00
```
2019-10-14 05:46:08 +08:00
### Rewriting the HTTP Host Header
2016-08-12 12:50:12 +08:00
2019-10-14 05:46:08 +08:00
By default frp does not modify the tunneled HTTP requests at all as it's a byte-for-byte copy.
2023-10-10 16:48:13 +08:00
However, speaking of web servers and HTTP requests, your web server might rely on the `Host` HTTP header to determine the website to be accessed. frp can rewrite the `Host` header when forwarding the HTTP requests, with the `hostHeaderRewrite` field:
2016-08-12 12:50:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["test.example.com"]
hostHeaderRewrite = "dev.example.com"
2016-08-12 12:50:12 +08:00
```
2022-08-29 12:25:36 +08:00
The HTTP request will have the `Host` header rewritten to `Host: dev.example.com` when it reaches the actual web server, although the request from the browser probably has `Host: test.example.com` .
2018-05-20 23:41:15 +08:00
2019-10-14 05:46:08 +08:00
### Setting other HTTP Headers
2018-05-20 23:41:15 +08:00
2019-10-14 05:46:08 +08:00
Similar to `Host` , You can override other HTTP request headers with proxy type `http` .
2018-05-20 23:41:15 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["test.example.com"]
hostHeaderRewrite = "dev.example.com"
requestHeaders.set.x-from-where = "frp"
2018-05-20 23:41:15 +08:00
```
2023-10-10 16:48:13 +08:00
In this example, it will set header `x-from-where: frp` in the HTTP request.
2016-08-12 12:50:12 +08:00
2017-07-17 00:57:10 +08:00
### Get Real IP
2019-04-10 13:39:26 +08:00
#### HTTP X-Forwarded-For
2019-10-14 05:46:08 +08:00
This feature is for http proxy only.
2017-07-17 00:57:10 +08:00
2022-01-09 23:47:28 +08:00
You can get user's real IP from HTTP request headers `X-Forwarded-For` .
2019-04-10 13:39:26 +08:00
#### Proxy Protocol
2019-10-14 05:46:08 +08:00
frp supports Proxy Protocol to send user's real IP to local services. It support all types except UDP.
2019-04-10 13:39:26 +08:00
Here is an example for https service:
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web"
type = "https"
localPort = 443
customDomains = ["test.example.com"]
2019-04-10 13:39:26 +08:00
2019-10-14 05:46:08 +08:00
# now v1 and v2 are supported
2023-10-10 16:48:13 +08:00
transport.proxyProtocolVersion = "v2"
2019-04-10 13:39:26 +08:00
```
2019-10-14 05:46:08 +08:00
You can enable Proxy Protocol support in nginx to expose user's real IP in HTTP header `X-Real-IP` , and then read `X-Real-IP` header in your web service for the real IP.
2019-04-10 13:39:26 +08:00
2020-03-05 21:47:49 +08:00
### Require HTTP Basic Auth (Password) for Web Services
2016-12-21 01:18:12 +08:00
Anyone who can guess your tunnel URL can access your local web server unless you protect it with a password.
2019-10-14 05:46:08 +08:00
This enforces HTTP Basic Auth on all requests with the username and password specified in frpc's configure file.
2016-12-21 01:18:12 +08:00
2017-05-18 19:08:43 +08:00
It can only be enabled when proxy type is http.
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["test.example.com"]
httpUser = "abc"
httpPassword = "abc"
2016-12-21 01:18:12 +08:00
```
2019-10-14 05:46:08 +08:00
Visit `http://test.example.com` in the browser and now you are prompted to enter the username and password.
2016-12-21 01:18:12 +08:00
2020-03-05 21:47:49 +08:00
### Custom Subdomain Names
2016-12-21 01:18:12 +08:00
2019-10-14 05:46:08 +08:00
It is convenient to use `subdomain` configure for http and https types when many people share one frps server.
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
subDomainHost = "frps.com"
2016-12-21 01:18:12 +08:00
```
2019-10-14 05:46:08 +08:00
Resolve `*.frps.com` to the frps server's IP. This is usually called a Wildcard DNS record.
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web"
type = "http"
localPort = 80
subdomain = "test"
2016-12-21 01:18:12 +08:00
```
2019-10-14 05:46:08 +08:00
Now you can visit your web service on `test.frps.com` .
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
Note that if `subdomainHost` is not empty, `customDomains` should not be the subdomain of `subdomainHost` .
2016-12-21 01:18:12 +08:00
2020-03-05 21:47:49 +08:00
### URL Routing
2016-12-28 00:26:50 +08:00
2019-10-14 05:46:08 +08:00
frp supports forwarding HTTP requests to different backend web services by url routing.
2016-12-28 00:26:50 +08:00
2019-10-14 05:46:08 +08:00
`locations` specifies 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.
2016-12-28 00:26:50 +08:00
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "web01"
type = "http"
localPort = 80
customDomains = ["web.example.com"]
locations = ["/"]
[[proxies]]
name = "web02"
type = "http"
localPort = 81
customDomains = ["web.example.com"]
locations = ["/news", "/about"]
2016-12-28 00:26:50 +08:00
```
2019-10-14 05:46:08 +08:00
HTTP requests with URL prefix `/news` or `/about` will be forwarded to **web02** and other requests to **web01** .
2020-03-11 14:13:16 +08:00
### TCP Port Multiplexing
2020-03-05 21:47:49 +08:00
2023-10-10 16:48:13 +08:00
frp supports receiving TCP sockets directed to different proxies on a single port on frps, similar to `vhostHTTPPort` and `vhostHTTPSPort` .
2020-03-05 21:47:49 +08:00
2020-03-11 14:13:16 +08:00
The only supported TCP port multiplexing method available at the moment is `httpconnect` - HTTP CONNECT tunnel.
2020-03-05 21:47:49 +08:00
2023-10-10 16:48:13 +08:00
When setting `tcpmuxHTTPConnectPort` to anything other than 0 in frps, frps will listen on this port for HTTP CONNECT requests.
2020-03-05 21:47:49 +08:00
2023-10-10 16:48:13 +08:00
The host of the HTTP CONNECT request will be used to match the proxy in frps. Proxy hosts can be configured in frpc by configuring `customDomains` and / or `subdomain` under `tcpmux` proxies, when `multiplexer = "httpconnect"` .
2020-03-05 21:47:49 +08:00
For example:
2023-10-10 16:48:13 +08:00
```toml
# frps.toml
bindPort = 7000
tcpmuxHTTPConnectPort = 1337
2020-03-05 21:47:49 +08:00
```
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
[[proxies]]
name = "proxy1"
type = "tcpmux"
multiplexer = "httpconnect"
customDomains = ["test1"]
localPort = 80
[[proxies]]
name = "proxy2"
type = "tcpmux"
multiplexer = "httpconnect"
customDomains = ["test2"]
localPort = 8080
2020-03-05 21:47:49 +08:00
```
In the above configuration - frps can be contacted on port 1337 with a HTTP CONNECT header such as:
```
CONNECT test1 HTTP/1.1\r\n\r\n
```
and the connection will be routed to `proxy1` .
2023-10-10 16:48:13 +08:00
### Connecting to frps via PROXY
2016-12-21 01:18:12 +08:00
2023-10-10 16:48:13 +08:00
frpc can connect to frps through proxy if you set OS environment variable `HTTP_PROXY` , or if `transport.proxyURL` is set in frpc.toml file.
2016-12-21 01:18:12 +08:00
2017-06-17 18:01:08 +08:00
It only works when protocol is tcp.
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
serverAddr = "x.x.x.x"
serverPort = 7000
transport.proxyURL = "http://user:pwd@192.168.1.128:8080"
2016-12-21 01:18:12 +08:00
```
2020-01-03 11:35:12 +08:00
### Client Plugins
2017-06-12 01:31:33 +08:00
2019-10-14 05:46:08 +08:00
frpc only forwards requests to local TCP or UDP ports by default.
2017-06-12 01:31:33 +08:00
2021-03-19 16:06:22 +08:00
Plugins are used for providing rich features. There are built-in plugins such as `unix_domain_socket` , `http_proxy` , `socks5` , `static_file` , `http2https` , `https2http` , `https2https` and you can see [example usage ](#example-usage ).
2017-06-12 01:31:33 +08:00
Using plugin **http_proxy** :
2023-10-10 16:48:13 +08:00
```toml
# frpc.toml
[[proxies]]
name = "http_proxy"
type = "tcp"
remotePort = 6000
[proxies.plugin]
type = "http_proxy"
httpUser = "abc"
httpPassword = "abc"
2017-06-12 01:31:33 +08:00
```
2023-10-10 16:48:13 +08:00
`httpUser` and `httpPassword` are configuration parameters used in `http_proxy` plugin.
2017-06-12 01:31:33 +08:00
2020-01-03 11:35:12 +08:00
### Server Manage Plugins
Read the [document ](/doc/server_plugin.md ).
2020-03-20 20:54:22 +08:00
Find more plugins in [gofrp/plugin ](https://github.com/gofrp/plugin ).
2016-03-14 16:18:29 +08:00
## Contributing
2016-06-03 18:15:01 +08:00
Interested in getting involved? We would like to help you!
2016-03-14 16:18:29 +08:00
2016-08-21 00:52:15 +08:00
* 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.
2019-10-02 03:58:35 +08:00
* Sorry for my poor English. Improvements for this document are welcome, even some typo fixes.
* If you have great ideas, send an email to fatedier@gmail.com.
2016-04-06 11:43:50 +08:00
2019-10-02 03:58:35 +08:00
**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 repeatedly.**
2016-06-03 18:15:01 +08:00
2016-08-24 13:36:38 +08:00
## Donation
2019-10-02 03:58:35 +08:00
If frp helps you a lot, you can support us by:
2016-08-24 13:36:38 +08:00
2022-01-26 20:56:00 +08:00
### GitHub Sponsors
2016-12-26 12:18:46 +08:00
2022-01-26 20:56:00 +08:00
Support us by [Github Sponsors ](https://github.com/sponsors/fatedier ).
2016-08-24 13:36:38 +08:00
2022-01-26 20:56:00 +08:00
You can have your company's logo placed on README file of this project.
2017-06-12 01:31:33 +08:00
2021-01-27 13:07:44 +08:00
### PayPal
2016-08-24 13:36:38 +08:00
2021-01-27 13:07:44 +08:00
Donate money by [PayPal ](https://www.paypal.me/fatedier ) to my account **fatedier@gmail.com** .