Table of Contents
什么是Frp

Frp 下载地址
https://github.com/fatedier/frp/releases
Frp 手册
服务端配置
公网的云主机上配置,注意防火墙配置建立入站规则 默认开启7000
- 下载
wget https://github.com/fatedier/frp/releases/download/v0.34.3/frp_0.34.3_linux_amd64.tar.gz
tar -vzxf frp_0.34.3_linux_amd64.tar.gz
mv frp_0.34.3_linux_amd64 frp
- 修改服务端配置
nano frps.ini
- 修改示例
https://gofrp.org/docs/examples/ -
启动命令
./frps -c ./frps.ini
客户端配置
任何可以上网的主机上
- 下载
wget https://github.com/fatedier/frp/releases/download/v0.34.3/frp_0.34.3_linux_arm.tar.gz
tar -vzxf frp_0.34.3_linux_arm.tar.gz
mv frp_0.34.3_linux_arm frp
- 修改客户端配置
nano frpc.ini
-
启动命令
./frpc -c ./frpc.ini
FRPC配置
# 该配置文件仅供参考。请勿直接使用此配置文件运行程序,因为可能存在各种问题。
# 你的代理名称将更改为 {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
# 控制台或实际日志文件路径,如 ./frpc.log
log.to = "./frpc.log"
# 日志级别:trace、debug、info、warn、error
log.level = "info"
log.maxDays = 3
# 当 log.to 是控制台时,禁用日志颜色,默认为 false
log.disablePrintColor = false
auth.method = "token"
# auth.additionalScopes 指定在身份验证信息中包含的附加范围。
# 可选值为 HeartBeats、NewWorkConns。
# auth.additionalScopes = ["HeartBeats", "NewWorkConns"]
# 身份验证令牌
auth.token = "12345678"
# oidc.clientID 指定在 OIDC 身份验证中获取令牌的客户端 ID。
# auth.oidc.clientID = ""
# oidc.clientSecret 指定在 OIDC 身份验证中获取令牌的客户端密钥。
# auth.oidc.clientSecret = ""
# oidc.audience 指定在 OIDC 身份验证中令牌的受众。
# auth.oidc.audience = ""
# oidc.scope 指定当 AuthenticationMethod == "oidc" 时,令牌的权限。默认值为 ""。
# auth.oidc.scope = ""
# oidc.tokenEndpointURL 指定实现 OIDC 令牌端点的 URL。
# 它将用于获取 OIDC 令牌。
# auth.oidc.tokenEndpointURL = ""
# oidc.additionalEndpointParams 指定要发送到 OIDC 令牌端点的附加参数。
# 例如,如果要指定 "audience" 参数,可以按如下方式设置。
# frp 将添加 "audience=<value>" 和 "var1=<value>" 到附加参数中。
# auth.oidc.additionalEndpointParams.audience = "https://dev.auth.com/api/v2/"
# auth.oidc.additionalEndpointParams.var1 = "foobar"
# 设置管理地址,用于通过 HTTP API 控制 frpc 的操作,例如重新加载
webServer.addr = "127.0.0.1"
webServer.port = 7400
webServer.user = "admin"
webServer.password = "admin"
# 管理资产目录。默认情况下,这些资产与 frpc 一起捆绑。
# webServer.assetsDir = "./static"
# 在管理监听器中启用 Golang pprof 处理程序。
webServer.pprofEnable = false
# 拨号到服务器的最大等待时间。默认值为 10 秒。
# transport.dialServerTimeout = 10
# dialServerKeepalive 指定 frpc 和 frps 之间的活动网络连接的保活探测间隔。
# 如果为负数,则禁用保活探测。
# transport.dialServerKeepalive = 7200
# 将预先建立连接,默认值为 0
transport.poolCount = 5
# 如果使用 TCP 流复用,默认值为 true,它必须与 frps 相同。
# transport.tcpMux = true
# 指定 TCP 复用的保活间隔。
# 仅当启用 tcpMux 时有效。
# transport.tcpMuxKeepaliveInterval = 30
# 用于连接服务器的通信协议
# 目前支持 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:passwd@192.168.1.128:8080"
# transport.proxyURL = "socks5://user:passwd@192.168.1.128:1080"
# transport.proxyURL = "ntlm://user:passwd@192.168.1.128: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
# 心跳配置,不建议修改默认值。
# heartbeatInterval 的默认值为 10,heartbeatTimeout 的默认值为 90。设置为负值可禁用它。
# transport.heartbeatInterval = 30
# transport.heartbeatTimeout = 90
# 指定 DNS 服务器,frpc 将使用此服务器而不是默认的
# 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 不为空,它将更改为 {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"
# 你可以通过注释向代理添加一些额外信息。
# 这些注释将显示在 frps 仪表板上。
[proxies.annotations]
key1 = "value1"
"prefix/key2" = "value2"
[[proxies]]
name = "ssh_random"
type = "tcp"
localIP = "192.168.31.100"
localPort = 22
# 如果 remotePort 为 0,frps 将为你分配一个随机端口
remotePort = 0
[[proxies]]
name = "dns"
type = "udp"
localIP = "114.114.114.114"
localPort = 53
remotePort = 6002
# 将某些服务暴露为 HTTP 或 HTTPS 服务
[[proxies]]
name = "web"
type = "http"
localPort = 8080
# frps 监听的域名
httpDomains = ["web.yourdomain.com"]
# 负载平衡 URL
loadBalancer.routeByHTTPUser = ["abc"]
loadBalancer.routeByHTTPHeader = ["xyz"]
# 传递给后端服务的 HTTP 请求头
healthCheck.healthCheckType = "http"
# 用于健康检查的路径
healthCheck.healthCheckURL = "/status"
# 可以在转发 HTTP 请求之前重写主机头
healthCheck.hostHeaderRewrite = "example.com"
# 用于 HTTPS 的 SSL 证书。
healthCheck.crtPath = "test.crt"
healthCheck.keyPath = "test.key"
# 如果 type 设置为 https,则忽略后端服务器的证书错误
healthCheck.skipVerifyBackendTLS = true
[[proxies]]
name = "web1"
type = "http"
localIP = "127.0.0.1"
localPort = 8080
httpSubDomain = "web01"
# 如果 httpUser 和 httpPassword 都为空,则此选项无效。
basicAuth.user = "abc"
basicAuth.password = "abc"
[[proxies]]
name = "web2"
type = "https"
localIP = "127.0.0.1"
localPort = 443
httpDomains = ["web02.yourdomain.com"]
healthCheck.healthCheckType = "http"
healthCheck.healthCheckURL = "/status"
healthCheck.crtPath = "test.crt"
healthCheck.keyPath = "test.key"
# 如果为 true,将跳过对后端服务的证书验证,默认为 false
healthCheck.skipVerifyBackendTLS = true
[[proxies]]
name = "unix"
type = "unix"
localPath = "/var/run/docker.sock"
remotePort = 6003
[[proxies]]
name = "unix_http"
type = "unix_http"
localPath = "/var/run/docker.sock"
remotePort = 6004
[[proxies]]
name = "tcp_random"
type = "tcp"
remotePort = 0
[[proxies]]
name = "udp_random"
type = "udp"
remotePort = 0
[[proxies]]
name = "secret_tcp"
type = "tcp"
localIP = "127.0.0.1"
localPort = 8080
remotePort = 6005
# 该代理的额外自定义属性。
# 客户端和服务器将使用相同的协议进行通信。
transport.customTransporterType = "secret"
[proxies.customTransporter]
key1 = "value1"
key2 = "value2"
[[proxies]]
name = "plugin_unix_domain_socket"
type = "tcp"
localIP = "127.0.0.1"
localPort = 9000
remotePort = 9001
transport.pluginType = "unix_domain_socket"
[proxies.plugin]
# 服务器套接字路径。
socketPath = "/var/run/proxy.sock"
# 客户端与代理通信的协议。
protocol = "tcp"
[[proxies]]
name = "plugin_https2http"
type = "https"
remotePort = 0
transport.pluginType = "https2http"
[proxies.plugin]
# 客户端和代理之间的连接超时。
timeout = "30s"
# https2http 插件的基本身份验证。
username = "abc"
password = "abc"
# 客户端和代理之间的 HTTP 头部。
[proxies.plugin.header]
Version = "1.0"
[[proxies]]
name = "plugin_https2https"
type = "https"
remotePort = 0
transport.pluginType = "https2https"
[proxies.plugin]
username = "abc"
password = "abc"
# 客户端和代理之间的 HTTPS 头部。
[proxies.plugin.header]
Version = "1.0"
# 用于客户端的 CA 证书。
caCertPath = "ca.crt"
[[proxies]]
name = "plugin_http2https"
type = "http"
remotePort = 0
transport.pluginType = "http2https"
[proxies.plugin]
username = "abc"
password = "abc"
[[proxies]]
name = "plugin_socks5"
type = "tcp"
localIP = "127.0.0.1"
localPort = 1080
remotePort = 0
transport.pluginType = "socks5"
[proxies.plugin]
username = "abc"
password = "abc"
[[proxies]]
name = "plugin_static_file"
type = "http"
localIP = "127.0.0.1"
localPort = 8080
httpSubDomain = "static"
remotePort = 0
transport.pluginType = "static_file"
[proxies.plugin]
pluginLocalPath = "/var/www/blog"
pluginStripPrefix = "/blog"
pluginHTML5 = true
[[proxies]]
name = "plugin_http_proxy"
type = "tcp"
remotePort = 0
transport.pluginType = "http_proxy"
[proxies.plugin]
username = "abc"
password = "abc"
[[proxies]]
name = "plugin_https_proxy"
type = "https"
remotePort = 0
transport.pluginType = "https_proxy"
[proxies.plugin]
username = "abc"
password = "abc"
FRPS配置
# 仅供参考的配置文件,请不要直接使用此配置运行程序,因为它可能存在各种问题。
# 对于IPv6的字面地址或主机名,必须用方括号括起来,如 "[::1]:80"、"[ipv6-host]:http" 或 "[ipv6-host%zone]:80"。
# 对于单个 "bindAddr" 字段,不需要方括号,如 `bindAddr = "::"`。
bindAddr = "0.0.0.0" # 服务器绑定的地址,"0.0.0.0" 表示监听所有网络接口。
bindPort = 7000 # 服务器监听的端口。
# 用于 KCP 协议的 UDP 端口,可以与 'bindPort' 相同。如果未设置,则在 frps 中禁用 KCP。
kcpBindPort = 7000 # KCP 协议的 UDP 端口。
# 用于 QUIC 协议的 UDP 端口。如果未设置,则在 frps 中禁用 QUIC。
# quicBindPort = 7002 # QUIC 协议的 UDP 端口。
# 指定代理监听的地址,默认值与 bindAddr 相同。
# proxyBindAddr = "127.0.0.1" # 代理绑定的地址。
# QUIC 协议选项
# transport.quic.keepalivePeriod = 10 # QUIC 协议的保活周期(秒)。
# transport.quic.maxIdleTimeout = 30 # QUIC 协议的最大空闲超时(秒)。
# transport.quic.maxIncomingStreams = 100000 # QUIC 协议的最大并发流数量。
# 心跳配置,不建议修改默认值。heartbeatTimeout 的默认值为 90。设置为负值可禁用心跳。
# transport.heartbeatTimeout = 90 # 心跳超时(秒)。
# 每个代理中保持的最大连接池数量。
transport.maxPoolCount = 5 # 连接池的最大数量。
# 是否使用 TCP 流复用,默认启用。
# transport.tcpMux = true # 启用 TCP 复用。
# 指定 TCP 复用的保活间隔时间,仅在 tcpMux 为 true 时有效。
# transport.tcpMuxKeepaliveInterval = 30 # TCP 复用的保活间隔(秒)。
# tcpKeepalive 指定 frpc 和 frps 之间活跃网络连接的保活探测间隔。如果为负值,则禁用保活探测。
# transport.tcpKeepalive = 7200 # TCP 保活探测间隔(秒)。
# transport.tls.force 指定是否只接受 TLS 加密连接。默认值为 false。
transport.tls.force = false # 强制 TLS 加密连接。
# transport.tls.certFile = "server.crt" # TLS 证书文件路径。
# transport.tls.keyFile = "server.key" # TLS 密钥文件路径。
# transport.tls.trustedCaFile = "ca.crt" # TLS 信任的根证书路径。
# 如果希望支持虚拟主机,必须设置用于监听的 HTTP 端口(可选)。
# 注意:HTTP 端口和 HTTPS 端口可以与 bindPort 相同。
vhostHTTPPort = 80 # 虚拟主机的 HTTP 端口。
vhostHTTPSPort = 443 # 虚拟主机的 HTTPS 端口。
# 虚拟主机 HTTP 服务器的响应超时时间(秒),默认是 60 秒。
# vhostHTTPTimeout = 60 # HTTP 响应超时(秒)。
# tcpmuxHTTPConnectPort 指定服务器监听 TCP HTTP CONNECT 请求的端口。
# 如果值为 0,服务器将不会在单一端口上复用 TCP 请求。默认值为 0。
# tcpmuxHTTPConnectPort = 1337 # TCP HTTP CONNECT 请求的监听端口。
# 如果 tcpmuxPassthrough 为 true,frps 将不会对流量进行任何处理。
# tcpmuxPassthrough = false # 是否启用 TCP 直通模式。
# 配置 Web 服务器以启用 frps 仪表板。
# 仪表板仅在设置了 webServer.port 时可用。
webServer.addr = "127.0.0.1" # 仪表板的绑定地址。
webServer.port = 7500 # 仪表板的监听端口。
webServer.user = "admin" # 仪表板的用户名。
webServer.password = "admin" # 仪表板的密码。
# webServer.tls.certFile = "server.crt" # 仪表板的 TLS 证书文件路径。
# webServer.tls.keyFile = "server.key" # 仪表板的 TLS 密钥文件路径。
# dashboard assets directory(only for debug mode)
# webServer.assetsDir = "./static" # 仪表板的静态资源目录(仅调试模式下使用)。
# 在仪表板监听器中启用 golang 的 pprof 调试功能。
# 必须先设置仪表板端口。
webServer.pprofEnable = false # 启用 pprof 调试。
# enablePrometheus 将在 webServer 中的 /metrics API 上导出 Prometheus 指标。
enablePrometheus = true # 启用 Prometheus 指标导出。
# 指定日志输出位置,可以是控制台或实际的日志文件路径,例如 "./frps.log"。
log.to = "./frps.log" # 日志输出路径。
# trace, debug, info, warn, error
log.level = "info" # 日志级别。
log.maxDays = 3 # 日志保留的最大天数。
# 当 log.to 是控制台时,禁用日志的颜色显示,默认值为 false。
log.disablePrintColor = false # 禁用日志颜色显示。
# DetailedErrorsToClient 定义是否向 frpc 发送特定的错误(包含调试信息)。默认值为 true。
detailedErrorsToClient = true # 向客户端发送详细错误信息。
# auth.method 指定用于验证 frpc 和 frps 的认证方法。
# 如果指定为 "token" - 将在登录消息中读取令牌。
# 如果指定为 "oidc" - 将使用 OIDC 设置颁发 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 颁发者。
# oidc audience 指定在验证时 OIDC 令牌应包含的受众。
auth.oidc.audience = "" # OIDC 受众。
# oidc skipExpiryCheck 指定是否跳过 OIDC 令牌过期检查。
auth.oidc.skipExpiryCheck = false # 跳过 OIDC 令牌过期检查。
# oidc skipIssuerCheck 指定是否跳过检查 OIDC 令牌的颁发者声明是否与 OidcIssuer 中指定的颁发者匹配。
auth.oidc.skipIssuerCheck = false # 跳过 OIDC 颁发者检查。
# userConnTimeout 指定工作连接的最大等待时间。
# userConnTimeout = 10 # 用户连接超时时间(秒)。
# 仅允许 frpc 绑定您列出的端口。默认情况下,不会有任何限制。
allowPorts = [
{ start = 2000, end = 3000 }, # 允许的端口范围,从 2000 到 3000。
{ single = 3001 }, # 允许的单个端口 3001。
{ single = 3003 }, # 允许的单个端口 3003。
{ start = 4000, end = 50000 } # 允许的端口范围,从 4000 到 50000。
]
# 每个客户端可以使用的最大端口数量,默认值为 0 表示无限制。
maxPortsPerClient = 0 # 每个客户端的最大端口数量。
# 如果 subDomainHost 不为空,则可以在 frpc 的配置文件中设置子域名类型为 http 或 https。
# 当子域名为 test 时,路由使用的主机名为 test.frps.com。
subDomainHost = "frps.com" # 子域名主机。
# 为 HTTP 请求指定自定义 404 页面。
# custom404Page = "/path/to/404.html" # 自定义 404 页面路径。
# 指定 UDP 数据包的大小,单位为字节。如果未设置,默认值为 1500。
# 该参数应在客户端和服务器之间保持一致。它会影响 UDP 和 sudp 代理。
udpPacketSize = 1500 # UDP 数据包大小(字节)。
# NAT 穿透策略数据的保留时间(小时)。
natholeAnalysisDataReserveHours = 168 # NAT 穿透策略数据保留时间(小时)。
# SSH 隧道网关
# 如果您想启用此功能,则需要配置 bindPort 参数,其他参数是可选的。
# 默认情况下,此功能是禁用的。如果 bindPort 大于 0,将启用此功能。
# sshTunnelGateway.bindPort = 2200 # SSH 隧道网关的绑定端口。
# sshTunnelGateway.privateKeyFile = "/home/frp-user/.ssh/id_rsa" # SSH 隧道网关的私钥文件路径。
# sshTunnelGateway.autoGenPrivateKeyPath = "" # 自动生成的私钥文件路径。
# sshTunnelGateway.authorizedKeysFile = "/home/frp-user/.ssh/authorized_keys" # 授权的公钥文件路径。
[[httpPlugins]]
name = "user-manager" # HTTP 插件名称。
addr = "127.0.0.1:9000" # 插件服务的地址。
path = "/handler" # 插件的处理路径。
ops = ["Login"] # 插件操作列表。
[[httpPlugins]]
name = "port-manager" # HTTP 插件名称。
addr = "127.0.0.1:9001" # 插件服务的地址。
path = "/handler" # 插件的处理路径。
ops = ["NewProxy"] # 插件操作列表。
文章评论