frp 是一个专注于内网穿透的高性能的反向代理应用,支持 TCP、UDP、HTTP、HTTPS 等多种协议。可以将内网服务以安全、便捷的方式通过具有公网 IP 节点的中转暴露到公网。

frp 分为服务端和客户端,以下用 frps 指代服务端,frpc 指代客户端

安装 frps

apt update && apt install curl jq -y

## 获取最新下载连接
export DOWNLOAD_URL=$(curl -s https://api.github.com/repos/fatedier/frp/releases/latest | jq -r '.assets[] | select(.name | endswith("_linux_amd64.tar.gz")) | .browser_download_url')

## 下载
wget -O frp_linux_amd64.tar.gz "$DOWNLOAD_URL"

## 解压
tar -xf frp_linux_amd64.tar.gz

## 进入目录
cd frp*linux_amd64

## 查看版本
./frps -v

配置 frps

以通过自定义域名访问内网的 Web 服务为例,更多示例见frps_full_example.toml或者官方文档。 修改frps.toml

## 监听地址和端口
bindAddr = "0.0.0.0"
bindPort = 7000

## 传输设置
transport.maxPoolCount = 5
transport.tcpMux = false
transport.tcpKeepalive = 7200
transport.heartbeatTimeout = 90
transport.tls.force = false

## 代理端口
vhostHTTPPort = 8080
vhostHTTPSPort = 4443

## log设置
log.to = "console"
log.level = "warn"
log.disablePrintColor = false
detailedErrorsToClient = true

## 验证密码
auth.method = "token"
auth.token = "123"

启动 frps

通过 PM2 启动 frps。点击查看 PM2 的安装和使用

pm2 start ./frps -n frps -- -c ./frps.toml

配置 frpc

frpc 的安装和启动同 frps

user = "xx"

## frps地址
serverAddr = "1.2.3.4"
serverPort = 7000

loginFailExit = false

## log设置
log.to = "console"
log.level = "warn"
log.disablePrintColor = false

## 验证密码
auth.method = "token"
auth.token = "123"

## 传输设置
transport.poolCount = 3
transport.tcpMux = false
transport.protocol = "tcp"
transport.tls.enable = false

## web1
[[proxies]]
name = "web1.com"
type = "https"
localIP = "127.0.0.1"
localPort = 100
customDomains = ["web1.com"]

## web2
[[proxies]]
name = "web2.com"
type = "http"
localIP = "127.0.0.1"
localPort = 101
customDomains = ["web2.com"]