1.安装frp
宝塔软件商店搜索“frp管理器”,点击安装,服务端即有公网ip端,客户端一般为本地虚拟主机。点击安装相应frp端。
2.文件配置
- 服务端
bindPort = 15443
kcpBindPort = 15443
dashboardPwd = "SKyuifmoagiwJ0tp" #web面板密码
vhostHTTPPort = 18080 #http
vhostHTTPSPort = 18443 #https
maxPoolCount = 5000
tcpmuxHTTPConnectPort = 16337
[webServer]
addr = "0.0.0.0" #宝塔不一定有,一定要加上
user = "fXTADFAP" #web面板账号
password = "SKyuifmoagiwJ0tp" #web面板密码
port = 7001 #web面板端口
[log]
file = "/var/log/frps.log"
level = "info"
maxDays = 30
[auth]
token = "trIOTrrfTlXN76io"
- 客户端
serverAddr = "公网ip"
serverPort = 15443
auth.token = "服务端最后一行token"
transport.tcpMax = true
[ssh]
name = "123456"
type = "tcp"
local_ip = "127.0.0.1"
local_port = 22
remote_port = 22
[[proxies]]
name = "web"
type = "http"
localPort = 9001 #代理本地9001端口,自行修改
customDomains = ["a.a.cn"] #绑定域名
3.nginx
进入文件路径/www/server/panel/vhost/nginx/创建frp.conf
#frp管理面板
server {
listen 80;
listen [::]:80;
server_name frp.xx.cn;#自行解析一个域名
location / {
proxy_set_header Host $host;
# 管理面板
proxy_pass http://127.0.0.1:7001;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
server {
listen 80;
listen [::]:80;
server_name a.a.cn;
#开启https,先放证书
#listen 443 ssl;
#charset utf-8;
# ssl_certificate /www/server/panel/vhost/nginx/frpssl/a.a.cn.pem;
# ssl_certificate_key /www/server/panel/vhost/nginx/frpssl/a.a.cn.key;
#强制开启https
# if ($server_port !~ 443){
# rewrite ^(/.*)$ https://$host$1 permanent;
# }
location / {
proxy_set_header Host $host;
#frp监听客户端http请求
proxy_pass http://127.0.0.1:18080;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}
4.重载nginx,完成
即frp.xx.cn,代理了虚拟机内网7001端口,访问就是frp网页管理页面。a.a.cn则代理9000端口。