FRP (fast reverse proxy )
证书创建
完整详细解释
第一步:创建 CA 根证书
CA(Certificate Authority)是证书颁发机构,相当于一个”公证处”,用它来签发服务端和客户端证书,建立信任链。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
openssl genrsa \ -out ca.key \ 4096
openssl req \ -new \ -x509 \ -days 3650 \ -key ca.key \ -out ca.crt \ -subj "/CN=FRP CA/O=MyOrg/C=CN"
|
第二步:创建服务端证书
服务端证书安装在 frps 上,frpc 连接时会验证这张证书是不是由受信任的 CA 签发的。
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
|
openssl genrsa \ -out server.key \ 2048
openssl req \ -new \ -key server.key \ -out server.csr \ -subj "/CN=frps-server/O=MyOrg/C=CN" \ -addext "subjectAltName = IP:192.168.61.27"
openssl x509 \ -req \ -days 3650 \ -in server.csr \ -CA ca.crt \ -CAkey ca.key \ -CAcreateserial \ -out server.crt -copy_extensions copy
|
1 2 3 4 5
| openssl req -new -x509 -days 3650 \ -key server.key \ -out server.crt \ -subj "/C=CN/ST=Guangdong/L=Guangzhou Huangpu District/O=Self-signed Certificate/OU=Private Use/CN=yukifuhane.cn.eu.org" \ -addext "subjectAltName = DNS:yukifuhane.cn.eu.org, DNS:192.168.6.3, IP:192.168.6.3"
|
第三步:创建客户端证书
客户端证书安装在 frpc 上,用于双向认证(mTLS)。frps 会验证连接过来的 frpc 是否持有合法证书,防止陌生客户端接入。
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
|
openssl genrsa \ -out client.key \ 2048
openssl req \ -new \ -key client.key \ -out client.csr \ -subj "/CN=frpc-client/O=MyOrg/C=CN"
openssl x509 \ -req \ -days 3650 \ -in client.csr \ -CA ca.crt \ -CAkey ca.key \ -CAcreateserial \ -out client.crt
|
信任链原理
1 2 3 4 5 6 7 8
| ca.key + ca.crt (自签,顶层信任锚) │ ├── 签发 ──▶ server.crt (frps 持有) │ frpc 验证:这张证书是我信任的 CA 签的 ✅ │ └── 签发 ──▶ client.crt (frpc 持有) frps 验证:这张证书是我信任的 CA 签的 ✅
|
双方都拿着同一个 ca.crt,谁的证书是这个 CA 签的,谁就可信。
各文件说明
1 2 3 4 5 6
| [transport.tls] force = true certFile = "server.crt" keyFile = "server.key" trustedCaFile = "ca.crt"
|
没啥关系,下面内容
自建CA证书
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| [req] distinguished_name = req_distinguished_name x509_extensions = v3_ca prompt = no default_md = sha256
[req_distinguished_name] C = CN ST = Shanghai L = Shanghai O = MyCompanyCA OU = Security_Dept CN = My_Private_Root_CA
[v3_ca]
basicConstraints = critical, CA:TRUE
keyUsage = critical, keyCertSign, cRLSign
subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer
|
1 2 3 4 5 6
| openssl genrsa -out ca.key 4048
openssl req -x509 -new -nodes -key ca.key -sha256 -days 36500 \ -out ca.crt -config ca.cnf
|
标准服务器证书
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
| [req] distinguished_name = req_distinguished_name req_extensions = v3_req prompt = no default_md = sha256
[req_distinguished_name]
C = CN ST = Shanghai L = Shanghai O = MyCompany OU = IT CN = my-service.local
[v3_req]
basicConstraints = critical, CA:FALSE
keyUsage = critical, digitalSignature, keyEncipherment
extendedKeyUsage = serverAuth, clientAuth
subjectKeyIdentifier = hash
subjectAltName = @alt_names
[alt_names]
DNS.1 = www.example.com DNS.2 = api.example.com DNS.3 = *.test.internal IP.1 = 192.168.1.100 IP.2 = 10.0.0.1
|
1 2 3 4 5 6 7 8 9
| openssl genrsa -out server.key 2048
openssl req -new -key server.key -out server.csr -config server.cnf
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial \ -out server.crt -days 3650 -extensions v3_req -extfile server.cnf
|
frps_example
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
|
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"]
|
frpc_example
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 465 466 467 468 469
|
clientID = "your_client_id"
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 = "tcp" 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"]
[proxies.natTraversal]
disableAssistedAddrs = false
[[proxies]] name = "vnet-server" type = "stcp" secretKey = "your-secret-key" [proxies.plugin] type = "virtual_net"
[[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
[visitors.natTraversal]
disableAssistedAddrs = false
[[visitors]] name = "vnet-visitor" type = "stcp" serverName = "vnet-server" secretKey = "your-secret-key" bindPort = -1 [visitors.plugin] type = "virtual_net" destinationIP = "100.86.0.1"
|