官方文档
1 2 3
| url: https://gofrp.org/ title: "/zh-cn/" host: gofrp.org
|
1 2 3 4
| url: https://blog.csdn.net/lihuayong/article/details/128575019 title: "FRP 内网穿透搭建(无域名)_frp搭建-CSDN博客" description: "文章浏览阅读3k次,点赞5次,收藏18次。frp是一种快速反向代理,可帮助您将NAT或防火墙后面的本地服务器暴露到Internet。到目前为止,它支持TCP和UDP,以及HTTP和HTTPS协议,其中请求可以通过域名转发到内部服务。_frp搭建" host: blog.csdn.net
|
编译
1 2 3 4 5
| url: https://www.wyr.me/post/737##toc1-3 title: "blog" description: "Yige Blog 2.0" host: www.wyr.me favicon: https://www.wyr.me/favicon.ico
|
1 2 3 4 5
| url: https://www.cnblogs.com/TianyuSu/p/11961994.html title: "frp 配置多个 web 项目,无需购买域名 (访问内网可视化界面,jupyter noterbook, visdom, tensorboard) - 佰大于 - 博客园" description: "通过一台外网服务器访问多台内网服务器。应用场景,调试内网web项目,深度学习展示loss,feature等图形" host: www.cnblogs.com favicon: https://assets.cnblogs.com/favicon_v3_2.ico
|
Fetching Data#t6ge
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 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 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 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 365 366 367 368 369 370 371 372 373 374 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 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
|
user = "your_name"
serverAddr = "0.0.0.0" serverPort = 7000
loginFailExit = true
log.to = "./frpc.log"
log.level = "info"
log.maxDays = 3
log.disablePrintColor = false
auth.method = "token"
auth.token = "12345678"
webServer.addr = "127.0.0.1" webServer.port = 7400 webServer.user = "admin" webServer.password = "admin"
webServer.pprofEnable = false
transport.poolCount = 5
transport.protocol = "tcp"
transport.connectServerLocalIP = "0.0.0.0"
transport.tls.enable = true
udpPacketSize = 1500
metadatas.var1 = "abc" metadatas.var2 = "123"
[[proxies]]
name = "ssh" type = "tcp" localIP = "127.0.0.1" localPort = 22
transport.bandwidthLimit = "1MB"
transport.bandwidthLimitMode = "client"
transport.useEncryption = false
transport.useCompression = false
remotePort = 6001
loadBalancer.group = "test_group"
loadBalancer.groupKey = "123456"
healthCheck.type = "tcp"
healthCheck.timeoutSeconds = 3
healthCheck.maxFailed = 3
healthCheck.intervalSeconds = 10
metadatas.var1 = "abc" metadatas.var2 = "123"
[proxies.annotations] key1 = "value1" "prefix/key2" = "value2" [[proxies]] name = "ssh_random" type = "tcp" localIP = "192.168.31.100" localPort = 22
remotePort = 0 [[proxies]] name = "dns" type = "udp" localIP = "114.114.114.114" localPort = 53 remotePort = 6002
[[proxies]] name = "web01" type = "http" localIP = "127.0.0.1" localPort = 80
httpUser = "admin" httpPassword = "admin"
subdomain = "web01" customDomains = ["web01.yourdomain.com"]
locations = ["/", "/pic"]
hostHeaderRewrite = "example.com" requestHeaders.set.x-from-where = "frp" responseHeaders.set.foo = "bar" healthCheck.type = "http"
healthCheck.path = "/status" healthCheck.intervalSeconds = 10 healthCheck.maxFailed = 3 healthCheck.timeoutSeconds = 3
healthCheck.httpHeaders=[ { name = "x-from-where", value = "frp" } ] [[proxies]] name = "web02" type = "https" localIP = "127.0.0.1" localPort = 8000 subdomain = "web02" customDomains = ["web02.yourdomain.com"]
transport.proxyProtocolVersion = "v2" [[proxies]] name = "tcpmuxhttpconnect" type = "tcpmux" multiplexer = "httpconnect" localIP = "127.0.0.1" localPort = 10701 customDomains = ["tunnel1"]
[[proxies]] name = "plugin_unix_domain_socket" type = "tcp" remotePort = 6003
[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" password = "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 = "plugin_http2http" type = "tcp" remotePort = 6007 [proxies.plugin] type = "http2http" localAddr = "127.0.0.1:80" hostHeaderRewrite = "127.0.0.1" requestHeaders.set.x-from-where = "frp" [[proxies]] name = "plugin_tls2raw" type = "https" remotePort = 6008 [proxies.plugin] type = "tls2raw" localAddr = "127.0.0.1:80" crtPath = "./server.crt" keyPath = "./server.key" [[proxies]] name = "secret_tcp"
type = "stcp"
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"]
[[visitors]] name = "secret_tcp_visitor" type = "stcp"
serverName = "secret_tcp" secretKey = "abcdefg"
bindAddr = "127.0.0.1"
bindPort = 9000 [[visitors]] name = "p2p_tcp_visitor" type = "xtcp"
serverUser = "user1" serverName = "p2p_tcp" secretKey = "abcdefg" bindAddr = "127.0.0.1"
bindPort = 9001
keepTunnelOpen = false
maxRetriesAnHour = 8 minRetryInterval = 90
frps.toml完整配置模板中文注释(0.60.0版本)
bindAddr = "0.0.0.0" bindPort = 7000
kcpBindPort = 7000
transport.maxPoolCount = 5
transport.tls.force = false
vhostHTTPPort = 80 vhostHTTPSPort = 443
webServer.addr = "127.0.0.1" webServer.port = 7500 webServer.user = "admin" webServer.password = "admin"
webServer.pprofEnable = false
enablePrometheus = true
log.to = "./frps.log"
log.level = "info" log.maxDays = 3
log.disablePrintColor = false
detailedErrorsToClient = true
auth.method = "token"
auth.token = "12345678"
auth.oidc.issuer = ""
auth.oidc.audience = ""
auth.oidc.skipExpiryCheck = false
auth.oidc.skipIssuerCheck = false
allowPorts = [ { start = 2000, end = 3000 }, { single = 3001 }, { single = 3003 }, { start = 4000, end = 50000 } ]
maxPortsPerClient = 0
subDomainHost = "frps.com"
udpPacketSize = 1500
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"]
|
服务端frp配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| [common] bind_port = 7500 vhost_http_port = 7501
authentication_method = token authenticate_new_work_conns = true token = 123321
dashboard_port = 7502
dashboard_user = xuanyue dashboard_pwd = xxxxx
|
客户端配置
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [common] server_addr = xxxxx server_port = 7500 authentication_method = token authenticate_new_work_conns = true token = 123xxxx
[web] type = http local_ip = 192.168.100.1 local_port = 80 custom_domains = xxxxx
locations = /
host_header_rewrite = 192.168.100.1
|
关于动态配置请求头,正常情况下是不需要使用这个参数的。
举个例子,比如你想通过 test.yourdomain.com
访问 www.baidu.com
。 虽然这个请求被转发到了百度的服务器,但是你发送的 http 请求的 header 中的 host 参数是 test.yourdomain.com,百度的后端服务可能会进行检测,如果 host 不是 www.baidu.com
就拒绝,返回相应错误。
这个时候,如果你设置 host_header_rewrite = www.baidu.com
,那么 frp 会将这个请求的 host 动态修改为 www.baidu.com
,百度的服务器看到的就是正常的请求,才能正常访问。
如果你后端的 nginx 启用了虚拟主机这样的功能,需要根据 host 做路由,那么你才需要配置这个参数。
ubuntu系统配置systemctl
systemctl系统和服务管理器
服务端配置 systemctl 来控制frps,自启动
vim /etc/systemd/system/frps.service
1 2 3 4 5 6 7 8 9 10 11 12 13
| [Unit]
Description = frps内网穿透服务 After = network.target syslog.target Wants = network.target
[Service] Type = simple
ExecStart = /root/App/frp/frps -c /root/App/frp/frps.toml
[Install] WantedBy = multi-user.target
|
1 2 3 4 5 6 7 8 9 10
| systemctl start frps
systemctl enable frps
systemctl restart frps
systemctl stop frps
systemctl status frps
|
URL 路由
frp 支持根据请求的 URL 路径路由转发到不同的后端服务。
通过配置文件中的 locations 字段指定一个或多个 proxy 能够匹配的 URL 前缀(目前仅支持最大前缀匹配,之后会考虑正则匹配)。例如指定 locations = "/news"
,则所有 URL 以 /news
开头的请求都会被转发到这个服务。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| [[proxies]] name = "web01" type = "http" localPort = 80 customDomains = ["web.yourdomain.com"] locations = ["/"]
[[proxies]] name = "web02" type = "http" localPort = 81 customDomains = ["web.yourdomain.com"] locations = ["/news", "/about"]
|
按照上述的示例配置后,web.yourdomain.com
这个域名下所有以 /news
以及 /about
作为前缀的 URL 请求都会被转发到 web02,其余的请求会被转发到 web01。
路由器配置举例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| [common] server_addr = 190.xxxx.xxxx.xxx server_port = 7500 authentication_method = token authenticate_new_work_conns = true token = xxx
[家里路由] type = http local_ip = 192.168.123.1 local_port = 80 custom_domains = 190.xxxx.xxxx.xxx host_header_rewrite = 192.168.123.1
[家里wifi] type = http local_ip = 192.168.0.1 local_port = 80 custom_domains = a.b.c
[路由ssh] type = tcp local_ip = 192.168.123.1 local_port = 22 remote_port = 7503
|