新版本 frp(0.52.0以后) 完整toml配置参考

说明

由于官方 至0.52.0 以后弃用了 ini配置文件,导致之前的配置全都失效了需要换下新的配置

以下是官方说明:从 v0.52.0 版本开始,frp 开始支持 TOML、YAML 和 JSON 作为配置文件格式。

这里我以toml  为例子 提供下基本完整的 frps.toml 与 frpc.toml

点击展开查看详情:

frps.toml 完整配置

# 对于IPv6,文字地址或主机名必须用方括号括起来,例如 "[::1]:80"、"[ipv6-host]:http" 或 "[ipv6-host%zone]:80"
# 对于单个 "bind_addr" 字段,不需要方括号,如 "bind_addr = ::"。
bindAddr = "0.0.0.0"
bindPort = 7000

# 用于 kcp 协议的 UDP 端口,可以与 'bind_port' 相同。
# 如果未设置,frps 将禁用 kcp。
kcpBindPort = 7000

# 用于 quic 协议的 UDP 端口。
# 如果未设置,frps 将禁用 quic。
# quicBindPort = 7002

# 指定代理将监听的地址,默认值与 bind_addr 相同。
# proxy_bind_addr = "127.0.0.1"

# quic 协议选项
# transport.quic.keepalivePeriod = 10
# transport.quic.maxIdleTimeout = 30
# transport.quic.maxIncomingStreams = 100000

# 心跳配置,不建议修改默认值
# heartbeat_timeout 的默认值是 90。设置为负值将其禁用。
# transport.heartbeatTimeout = 90

# 每个代理中保留的池计数不超过 maxPoolCount。
transport.maxPoolCount = 5

# 如果使用了 tcp 流复用,则默认值为 true
# transport.tcpMux = true

# 指定 tcp mux 的保持活动间隔。
# 仅当 tcpMux 为 true 时有效。
# transport.tcpMuxKeepaliveInterval = 60

# tcpKeepalive 指定 frpc 和 frps 之间主动网络连接的保持活动探测之间的间隔。
# 如果为负值,将禁用保活探测。
# transport.tcpKeepalive = 7200

# transport.tls.force 指定是否只接受 TLS 加密连接。默认情况下,该值为 false。
tls.force = false

# transport.tls.certFile = "server.crt"
# transport.tls.keyFile = "server.key"
# transport.tls.trustedCaFile = "ca.crt"

# 如果要支持虚拟主机,必须设置用于监听的 http 端口(可选)
# 注意:http 端口和 https 端口可以与 bind_port 相同
vhostHTTPPort = 80
vhostHTTPSPort = 443

# vhost http 服务器的响应头超时(秒),默认为 60 秒
# vhostHTTPTimeout = 60

# tcpmuxHTTPConnectPort 指定服务器监听 TCP HTTP CONNECT 请求的端口。
# 如果值为 0,则服务器将不会在一个单一端口上复用 TCP 请求。
# 如果不是 - 它将在此值上监听 HTTP CONNECT 请求。默认情况下,此值为 0。
# tcpmuxHTTPConnectPort = 1337

# 如果 tcpmux_passthrough 为 true,则 frps 不会对流量进行任何更新。
# tcpmuxPassthrough = false

# 配置 web 服务器以启用 frps 的仪表板。
# 仪表板仅在设置了 webServer.port 时可用。
webServer.addr = "127.0.0.1"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "admin"
# webServer.tls.certFile = "server.crt"
# webServer.tls.keyFile = "server.key"
# 仪表板资源目录(仅限调试模式)
# webServer.assetsDir = "./static"

# 在仪表板监听器中启用 golang pprof 处理程序。
# 必须首先设置仪表板端口
webServer.pprofEnable = false

# enablePrometheus 将在 webServer 上的 /metrics API 导出 Prometheus 指标。
enablePrometheus = true

# 控制台或实际 logFile 路径,如 ./frps.log
log.to = "./frps.log"
# trace、debug、info、warn、error
log.level = "info"
log.maxDays = 3
# 当 log.to 为 console 时禁用日志颜色,默认值为 false
log.disablePrintColor = false

# DetailedErrorsToClient 定义是否将具体错误(带有调试信息)发送给 frpc。默认情况下,此值为 true。
detailedErrorsToClient = true

# auth.method 指定要使用的身份验证方法来验证 frpc 与 frps。
# 如果指定了 "token" - 令牌将读取到登录消息。
# 如果指定了 "oidc" - 将使用 OIDC(Open ID Connect)设置发行 OIDC 令牌。默认情况下,此值为 "token"。
auth.method = "token"

# auth.additionalScopes 指定要包含在身份验证信息中的附加范围。
# 可选值为 HeartBeats、NewWorkConns。
# auth.additionalScopes = ["HeartBeats", "NewWorkConns"]

# auth token
auth.token = "12345678"

# oidc issuer 指定要验证 OIDC 令牌的发行方。
auth.oidc.issuer = ""
# oidc audience 指定在验证时 OIDC 令牌应包含的受众。
auth.oidc.audience = ""
# oidc skipExpiryCheck 指定是否跳过检查 OIDC 令牌是否过期。
auth.oidc.skipExpiryCheck = false
# oidc skipIssuerCheck 指定是否跳过检查 OIDC 令牌的发行方声明是否与 oidc.issuer 中指定的发行方相匹配。
auth.oidc.skipIssuerCheck = false

# userConnTimeout 指定等待工作连接的最长时间。
# userConnTimeout = 10

# 仅允许 frpc 绑定你列出的端口。默认情况下,不会有任何限制。
allowPorts = [
{ start = 2000, end = 3000 },
{ single = 3001 },
{ single = 3003 },
{ start = 4000, end = 50000 }
]

# 每个客户端可用的最大端口数,默认值为 0 表示无限制
maxPortsPerClient = 0

# 如果 subDomainHost 不为空,可以在 frpc 的配置文件中设置类型为 http 或 https 时的子域名
# 当子域名为 "est" 时,路由使用的主机是 test.frps.com
subDomainHost = "frps.com"

# 用于 HTTP 请求的自定义 404 页面
# custom404Page = "/path/to/404.html"

# 指定 UDP 数据包大小,单位为字节。如果未设置,默认值为 1500。
# 此参数应在客户端和服务器之间相同。
# 它影响 udp 和 sudp 代理。
udpPacketSize = 1500

# 用于 NAT 穿透策略数据的保留时间。
natholeAnalysisDataReserveHours = 168

[[httpPlugins]]
name = "user-manager"
addr = "127.0.0.1:9000"
path = "/handler"
ops = ["Login"]

[[httpPlugins]]
name = "port-manager"
addr = "127.0.0.1:9001"
path = "/handler"
ops = ["NewProxy"]


frpc.toml 完整配置

# 代理名称将更改为 {user}.{proxy}
user = "your_name"

# 对于IPv6,文字地址或主机名必须用方括号括起来,例如 "[::1]:80"、"[ipv6-host]:http" 或 "[ipv6-host%zone]:80"
# 对于单个 serverAddr 字段,不需要方括号,例如 serverAddr = "::"。
serverAddr = "0.0.0.0"
serverPort = 7000

# 用于帮助穿透 NAT 孔的 STUN 服务器。
# natHoleStunServer = "stun.easyvoip.com:3478"

# 决定在第一次登录失败时是否退出程序,否则将继续重新登录到 frps。
# 默认值为 true。
loginFailExit = true

# 控制台或实际 logFile 路径,例如 ./frpc.log
# trace、debug、info、warn、error
log.to = "./frpc.log"
log.level = "info"
log.maxDays = 3
# 当 log.to 为 console 时禁用日志颜色,默认值为 false
log.disablePrintColor = false

auth.method = "token"
# auth.additionalScopes 指定要包含在身份验证信息中的附加范围。
# 可选值为 HeartBeats、NewWorkConns。
# auth.additionalScopes = ["HeartBeats", "NewWorkConns"]

# auth token
auth.token = "12345678"

# oidc.clientID 指定在 OIDC 身份验证中用于获取令牌的客户端 ID。
# auth.oidc.clientID = ""
# oidc.clientSecret 指定在 OIDC 身份验证中用于获取令牌的客户端密钥。
# auth.oidc.clientSecret = ""
# oidc.audience 指定 OIDC 身份验证中令牌的受众。
# auth.oidc.audience = ""
# oidc_scope 指定 OIDC 身份验证中令牌的权限,如果 AuthenticationMethod == "oidc"。默认情况下,此值为 ""。
# auth.oidc.scope = ""
# oidc.tokenEndpointURL 指定实现 OIDC Token Endpoint 的 URL。
# 它将用于获取 OIDC 令牌。
# auth.oidc.tokenEndpointURL = ""

# oidc.additionalEndpointParams 指定要发送到 OIDC Token Endpoint 的附加参数。
# 例如,如果要指定 "audience" 参数,可以设置如下。
# frp 将添加 "audience=<value>" "var1=<value>" 到附加参数中。
# auth.oidc.additionalEndpointParams.audience = "https://dev.auth.com/api/v2/"
# auth.oidc.additionalEndpointParams.var1 = "foobar"

# 为控制 frpc 操作提供 http api 的管理员地址,例如 reload
webServer.addr = "127.0.0.1"
webServer.port = 7400
webServer.user = "admin"
webServer.password = "admin"
# 管理员资源目录。默认情况下,这些资源与 frpc 捆绑在一起。
# webServer.assetsDir = "./static"

# 在管理员监听器中启用 golang pprof 处理程序。
webServer.pprofEnable = false

# 对 frpc 到服务器的拨号等待连接完成的最大时间量。默认值为 10 秒。
# transport.dialServerTimeout = 10

# dialServerKeepalive 指定 frpc 和 frps 之间主动网络连接的保持活动探测之间的间隔。
# 如果为负值,将禁用保活探测。
# transport.dialServerKeepalive = 7200

# 事先建立连接的数量,默认值为零
transport.poolCount = 5

# 如果使用了 tcp 流复用,则默认值为 true,它必须与 frps 相同
# transport.tcpMux = true

# 指定 tcp mux 的保持活动间隔。
# 仅当启用 tcpMux 时有效。
# transport.tcpMuxKeepaliveInterval = 60

# 用于连接到服务器的通信协议
# 现在支持 tcp、kcp、quic、websocket 和 wss,默认为 tcp
transport.protocol = "tcp"

# 在连接服务器时设置客户端绑定 IP, 默认为空。
# 仅当协议为 tcp 或 websocket 时,该值将被使用。
transport.connectServerLocalIP = "0.0.0.0"

# 如果您想通过 http 代理或 socks5 代理或 ntlm 代理连接 frps,您可以在此处或全局环境变量中设置 proxyURL
# 它仅在协议为 tcp 时起作用
# transport.proxyURL = "http://user:[email protected]:8080"
# transport.proxyURL = "socks5://user:[email protected]:1080"
# transport.proxyURL = "ntlm://user:[email protected]:2080"

# quic 协议选项
# transport.quic.keepalivePeriod = 10
# transport.quic.maxIdleTimeout = 30
# transport.quic.maxIncomingStreams = 100000

# 如果 tls.enable 为 true,frpc 将通过 tls 连接到 frps。
# 自 v0.50.0 起,默认值已更改为 true,且默认情况下启用 tls。
transport.tls.enable = true

# transport.tls.certFile = "client.crt"
# transport.tls.keyFile = "client.key"
# transport.tls.trustedCaFile = "ca.crt"
# transport.tls.serverName = "example.com"

# 如果 disableCustomTLSFirstByte 设置为 false,则在启用 tls 时,frpc 将使用第一个自定义字节与 frps 建立连接。
# 自 v0.50.0 起,默认值已更改为 true,默认情况下禁用第一个自定义字节。
# transport.tls.disableCustomTLSFirstByte = true

# 心跳配置,不建议修改默认值。
# heartbeat_interval 默认值为 10,heartbeat_timeout 默认值为 90。设置负值将禁用它。
# transport.heartbeatInterval = 30
# transport.heartbeatTimeout = 90

# 指定一个 DNS 服务器,这样 frpc 将使用它而不是默认的 DNS。
# dnsServer = "8.8.8.8"

# 要启动的代理名称。
# 默认为空,表示所有代理。
# start = ["ssh", "dns"]

# 指定 udp 数据包大小,单位为字节。如果未设置,默认值为 1500。
# 此参数应在客户端和服务器之间相同。
# 它影响 udp 和 sudp 代理。
udpPacketSize = 1500

# 用于客户端的其他元数据。
metadatas.var1 = "abc"
metadatas.var2 = "123"

# 包含代理的其他配置文件。
# includes = ["./confd/*.ini"]

[[proxies]]
# 'ssh' 是唯一的代理名称
# 如果全局用户不为空,它将更改为 {user}.{proxy},例如 'your_name.ssh'
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
# 限制此代理的带宽,单位为 KB 和 MB
transport.bandwidthLimit = "1MB"
# 限制带宽的位置,可以是 'client' 或 'server',默认为 'client'
transport.bandwidthLimitMode = "client"
# 如果为 true,此代理的流量将被加密,默认为 false
transport.useEncryption = false
# 如果为 true,流量将被压缩
transport.useCompression = false
# frps 监听的远程端口
remotePort = 6001
# frps 将为同一组中的代理负载均衡连接
loadBalancer.group = "test_group"
# 组应该有相同的组密钥
loadBalancer.groupKey = "123456"
# 为后端服务启用健康检查,现在支持 'tcp' 和 'http'。
# frpc 将连接本地服务的端口以检测其健康状态
healthCheck.type = "tcp"
# 健康检查连接超时
healthCheck.timeoutSeconds = 3
# 如果连续 3 次失败,代理将从 frps 中删除
healthCheck.maxFailed = 3
# 每 10 秒进行一次健康检查
healthCheck.intervalSeconds = 10
# 为每个代理的其他元数据
metadatas.var1 = "abc"
metadatas.var2 = "123"

[[proxies]]
name = "ssh_random"
type = "tcp"
localIP = "192.168.31.100"
localPort = 22
# 如果 remote_port 为 0,frps 将为您分配一个随机端口
remotePort = 0

[[proxies]]
name = "dns"
type = "udp"
localIP = "114.114.114.114"
localPort = 53
remotePort = 6002

# 将域名解析为 [server_addr],这样您就可以使用 http://web01.yourdomain.com 浏览 web01,
# 并使用 http://web02.yourdomain.com 浏览 web02
[[proxies]]
name = "web01"
type = "http"
localIP = "127.0.0.1"
localPort = 80
# http 用户名和密码是 http 协议的安全认证
# 如果不设置,您可以在没有认证的情况下访问这些自定义域名
httpUser = "admin"
httpPassword = "admin"
# 如果 frps 的域名为 frps.com,那么您可以通过 URL http://web01.frps.com 访问 [web01] 代理
subdomain = "web01"
customDomains = ["web01.yourdomain.com"]
# 仅对 http 类型可用的 locations
locations = ["/", "/pic"]
# 如果 http 基本自动用户为 abc,则将请求路由到此服务
# route_by_http_user = abc
hostHeaderRewrite = "example.com"
# 具有前缀 "header_" 的参数将用于更新 http 请求头
requestHeaders.set.x-from-where = "frp"
healthCheck.type = "http"
# frpc 将向本地 http 服务发送 GET http 请求 '/status'
# 只要它返回 2xx http 响应代码,http 服务就是活动的
healthCheck.path = "/status"
healthCheck.intervalSeconds = 10
healthCheck.maxFailed = 3
healthCheck.timeoutSeconds = 3

[[proxies]]
name = "web02"
type = "https"
localIP = "127.0.0.1"
localPort = 8000
subdomain = "web02"
customDomains = ["web02.yourdomain.com"]
# 如果不为空,frpc 将使用代理协议将连接信息传输到本地服务
# v1 或 v2 或为空
transport.proxyProtocolVersion = "v2"

[[proxies]]
name = "tcpmuxhttpconnect"
type = "tcpmux"
multiplexer = "httpconnect"
localIP = "127.0.0.1"
localPort = 10701
customDomains = ["tunnel1"]
# routeByHTTPUser = "user1"

[[proxies]]
name = "plugin_unix_domain_socket"
type = "tcp"
remotePort = 6003
# 如果定义了插件,则 local_ip 和 local_port 无效
# 插件将处理从 frps 获取的连接
[proxies.plugin]
type = "unix_domain_socket"
unixPath = "/var/run/docker.sock"

[[proxies]]
name = "plugin_http_proxy"
type = "tcp"
remotePort = 6004
[proxies.plugin]
type = "http_proxy"
httpUser = "abc"
httpPassword = "abc"

[[proxies]]
name = "plugin_socks5"
type = "tcp"
remotePort = 6005
[proxies.plugin]
type = "socks5"
username = "abc

[[proxies]]
name = "plugin_static_file"
type = "tcp"
remotePort = 6006
[proxies.plugin]
type = "static_file"
localPath = "/var/www/blog"
stripPrefix = "static"
httpUser = "abc"
httpPassword = "abc"

[[proxies]]
name = "plugin_https2http"
type = "https"
customDomains = ["test.yourdomain.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"

[[proxies]]
name = "plugin_https2https"
type = "https"
customDomains = ["test.yourdomain.com"]
[proxies.plugin]
type = "https2https"
localAddr = "127.0.0.1:443"
crtPath = "./server.crt"
keyPath = "./server.key"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

[[proxies]]
name = "plugin_http2https"
type = "http"
customDomains = ["test.yourdomain.com"]
[proxies.plugin]
type = "http2https"
localAddr = "127.0.0.1:443"
hostHeaderRewrite = "127.0.0.1"
requestHeaders.set.x-from-where = "frp"

[[proxies]]
name = "secret_tcp"
# 如果类型为 secret tcp,则 remote_port 无效
# 想要连接本地端口的人应该部署另一个带有 stcp 代理和角色为 visitor 的 frpc
type = "stcp"
# secretKey 用于访客的身份验证
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
# 如果非空,则只允许来自指定用户的访客连接
# 否则,来自同一用户的访客可以连接。'*' 表示允许所有用户。
allowUsers = ["*"]

[[proxies]]
name = "p2p_tcp"
type = "xtcp"
secretKey = "abcdefg"
localIP = "127.0.0.1"
localPort = 22
# 如果非空,则只允许来自指定用户的访客连接
# 否则,来自同一用户的访客可以连接。'*' 表示允许所有用户。
allowUsers = ["user1", "user2"]

# frpc 角色 visitor -> frps -> frpc 角色 server
[[visitors]]
name = "secret_tcp_visitor"
type = "stcp"
# 您要访问的服务器名称
serverName = "secret_tcp"
secretKey = "abcdefg"
# 将此地址连接到 visitor stcp 服务器
bindAddr = "127.0.0.1"
# bindPort 可以小于 0,表示不绑定到端口,只接收从其他访客重定向的连接(目前不支持 SUDP)
bindPort = 9000

[[visitors]]
name = "p2p_tcp_visitor"
type = "xtcp"
# 如果未设置服务器用户,则默认为当前用户
serverUser = "user1"
serverName = "p2p_tcp"
secretKey = "abcdefg"
bindAddr = "127.0.0.1"
# bindPort 可以小于 0,表示不绑定到端口,只接收从其他访客重定向的连接(目前不支持 SUDP)
bindPort = 9001
# 当需要自动隧道持久性时,将其设置为 true
keepTunnelOpen = false
# keep_tunnel_open 设置为 true 时生效,每小时尝试穿透的次数
maxRetriesAnHour = 8
minRetryInterval = 90
# fallbackTo = "stcp_visitor"
# fallbackTimeoutMs = 500

 

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注