场景:本地调试微信生态的回调时,如果全用线上调试,那就太恶心人了,所以我们今天简单说下frp内网穿透
一、安装和配置
frp下载地址:
https://github.com/fatedier/frp/releases
简单说一下:
服务器用的是frps,客户端用的是frpc,对应的配置就是对应的toml
客户端配置
# 服务器IP地址
serverAddr = "182.*.*.*"
# 服务器对应绑定端口
serverPort = 15443
auth.token = "C0mAAnJkgrrc56DL"
transport.tcpMax = true
[[proxies]]
name = "web"
type = "http"
# 本地运行项目对应的端口
localPort = 8000
# 映射的域名
customDomains = ["a.test.cn"]
服务端配置
# 服务端绑定的端口
bindPort = 15443
kcpBindPort = 15443
webServer.port = 6001
webServer.user = "bnX1IwgA"
webServer.password = "d8gZciK6KmrFp2rj"
vhostHTTPPort = 18080
vhostHTTPSPort = 18443
auth.token = "C0mAAnJkgrrc56DL"
二、运行
# 先运行服务端,即我们的服务器
./frps -c ./frps.toml
# 后运行客户端,即我们本地电脑
./frpc -c ./frpc.toml
因为服务端我们的80端口一般被nginx占用了,所以我们直接访问 a.test.cn:18080就可以了
三、骚操作
因为我们的指向的是18080端口,但是一般微信需要我们直接使用80端口,那么我们直接配置nginx的vhost再转一次域名就ok了,这样我们就可以直接使用另一个域名的80端口,访问了
location ^~ / {
proxy_pass "http://a.test.cn:18080/";
}
四、systemctl配置服务项
# 在/etc/systemd/system目录添加frp.service文件,为以下内容,更改对应的ExecStart选项
[Unit]
Description=Frp Service
After=network.target
[Service]
ExecStart=/www/wwwroot/frp/frps -c /www/wwwroot/frp/frps.toml
Restart=on-failure
RestartSec=10s
WorkingDirectory=/www/wwwroot/frp
# 重载
sudo systemctl daemon-reload
# 启动
systemctl start frp
# 获取状态
systemctl status frp