一、前置准备
1.硬件准备
- 带有 公网IP 的云服务器( 系统:centos 7 )
- 需要 内网穿透 的服务器(Linux、Windows)
- 域名
2.软件准备
二、安装 FRPS
注意:此客户端安装在有公网IP的机器
1.创建文件夹
| 12
 
 | cd mkdir -p /root/frp/server
 
 | 
2.创建配置文件
从 v0.52.0 版本开始,frp 开始支持 TOML、YAML 和 JSON 作为配置文件格式
| 12
 
 | cd /root/frp/servervi frps.toml
 
 | 
3.配置 frps.toml
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 
 | # 服务端监听端口bindPort = 7000
 # http代理监听端口
 vhostHTTPPort = 7001
 # https代理监听端口
 vhostHTTPSPort = 7002
 # 鉴权方式
 auth.method = "token"
 # 客户端连接的token,相当于密码
 auth.token = "password"
 
 # 服务端UI界面端口
 webServer.port = 7500
 webServer.addr = "0.0.0.0"
 # dashboard's username and password are both optional
 webServer.user = "admin"
 webServer.password = "password"
 
 | 
vi 命令保存退出命令的方法:
1.ESC键
2.输入 :wq 
4.运行 docker 容器
| 1
 | docker run -d -p 7000:7000 -p 7001:7001 -p 7002:7002 -p 7500:7500 -v /root/frp/server/frps.toml:/etc/frp/frps.toml --name frps snowdreamtech/frps
 | 
5.开放端口
开放 7000 - 7002 & 7500 端口
6.访问服务端UI
http://公网IP:7500/ 访问UI界面
访问账户和密码在 frps.toml 中配置(默认账户:admin 默认密码:password)
 
三、安装FRPC
注意:此客户端安装在需要穿透的机器
1.Linux客户端
| 12
 
 | cd mkdir -p /root/frp/client
 
 | 
从 v0.52.0 版本开始,frp 开始支持 TOML、YAML 和 JSON 作为配置文件格式
| 12
 
 | cd /root/frp/clientvi frpc.toml
 
 | 
注意:配置要与服务器 frps.toml 对应
| 12
 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
 
 | serverAddr = "公网IP"serverPort = 7000
 
 # 与服务端保持一致
 auth.method = "token"
 auth.token = "password"
 
 [[proxies]]
 name = "test-http"
 type = "tcp"
 localIP = "127.0.0.1"        	   	# 需要暴露的服务的IP
 localPort = 9000            	   	# 将本地9000端口的服务暴露在公网的6060端口
 remotePort = 6060           	   	# 暴露服务的公网入口
 
 [[proxies]]
 name = "web_web"
 type = "http"
 localPort = 8080				   	# 本地应用端口
 customDomains = ["yourdomain.com"] 	# 域名,指向你的公网IP
 
 [[proxies]]
 name = "web_https"
 type = "https"
 customDomains = ["yourdomain.com"] 	# 域名,指向你的公网IP
 
 [proxies.plugin]
 type = "https2http"
 localAddr = "127.0.0.1:8080"	   	# 本地应用端口
 
 # HTTPS 证书相关的配置,修改证书文件路径
 crtPath = "ssl/fullchain.pem"
 keyPath = "ssl/privkey.pem"
 hostHeaderRewrite = "127.0.0.1"
 requestHeaders.set.x-from-where = "frp"
 
 | 
vi 命令保存退出命令的方法:
1.ESC键
2.输入 :wq
| 1
 | docker run --restart=always --network host -itd -v /root/frp/client/frpc.toml:/etc/frp/frpc.toml --name frpc snowdreamtech/frpc
 | 
2.Windows客户端
下载地址:https://github.com/fatedier/frp/releases
下载样式:frp_0.x.x_windows_amd64.zip
注意:配置要与服务器 frps.toml 对应
| 12
 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
 
 | serverAddr = "公网IP"serverPort = 7000
 
 # 与服务端保持一致
 auth.method = "token"
 auth.token = "password"
 
 [[proxies]]
 name = "test-http"
 type = "tcp"
 localIP = "127.0.0.1"        	   	# 需要暴露的服务的IP
 localPort = 9000            	   	# 将本地9000端口的服务暴露在公网的6060端口
 remotePort = 6060           	   	# 暴露服务的公网入口
 
 [[proxies]]
 name = "web_web"
 type = "http"
 localPort = 8080				   	# 本地应用端口
 customDomains = ["yourdomain.com"] 	# 域名,指向你的公网IP
 
 [[proxies]]
 name = "web_https"
 type = "https"
 customDomains = ["yourdomain.com"] 	# 域名,指向你的公网IP
 
 [proxies.plugin]
 type = "https2http"
 localAddr = "127.0.0.1:8080"	   	# 本地应用端口
 
 # HTTPS 证书相关的配置,修改证书文件路径
 crtPath = "ssl/fullchain.pem"
 keyPath = "ssl/privkey.pem"
 hostHeaderRewrite = "127.0.0.1"
 requestHeaders.set.x-from-where = "frp"
 
 | 
frp的客户端不能直接通过exe文件启动,这里我们建一个bat脚本,写入以下内容
 
四、运行说明
1.TCP协议
当使用 TCP 协议,当穿透成功时可以从 公网IP:设置端口 访问
2.HTTP(S)协议
frps.toml 中的 http代理监听端口 需要修改为 80 才能正常使用
frps.toml 中的 https代理监听端口 需要修改为 443 才能正常使用
如果 80 端口被 Nginx 占用请参考 FRP与Nginx共存教程
域名需要解析到 服务器IP 
