如何在VPS上部署FRP实现内网穿透?
| 配置参数 |
说明 |
默认值 |
建议值 |
| bindPort |
服务端与客户端通信端口 |
7000 |
7000-8000 |
| vhostHTTPPort |
HTTP代理监听端口 |
80 |
80⁄8080 |
| vhostHTTPSPort |
HTTPS代理监听端口 |
443 |
443 |
| kcpBindPort |
KCP协议端口 |
7000 |
7000 |
| quicBindPort |
QUIC协议端口 |
7002 |
7002 |
| transport.maxPoolCount |
最大连接池大小 |
5 |
10-20 |
| transport.tcpMux |
TCP多路复用 |
true |
true |
| transport.tls.force |
强制TLS加密 |
false |
true(生产环境) |
VPS部署FRP实现内网穿透的完整指南
FRP(Fast Reverse Proxy)是一款高性能的反向代理应用,支持TCP、UDP、HTTP、HTTPS等多种协议,能够将内网服务安全地暴露到公网。本文将详细介绍在VPS上部署FRP的完整流程,包括配置参数、常见问题解决方案和性能优化建议。
一、FRP部署前的准备工作
- VPS选择:建议选择具有公网IP的Linux VPS,配置至少1核CPU、1GB内存和10Mbps带宽
- 系统要求:支持Ubuntu 18.04+/CentOS 7+等主流Linux发行版
- 端口准备:确保VPS防火墙开放以下端口:
- 服务端通信端口(bindPort)
- HTTP/HTTPS代理端口(vhostHTTPPort/vhostHTTPSPort)
- KCP/QUIC协议端口(如使用)
二、FRP服务端部署步骤
1. 下载FRP最新版本
wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp0.61.1linuxamd64.tar.gz
tar -zxvf frp0.61.1linuxamd64.tar.gz
cd frp0.61.1linuxamd64
2. 配置frps.toml文件
[common]
bindPort = 7000
bindAddr = "0.0.0.0"
token = "yoursecuretoken"
Web管理界面
webServer.addr = "0.0.0.0"
webServer.port = 7500
webServer.user = "admin"
webServer.password = "adminpassword"
HTTP/HTTPS代理
vhostHTTPPort = 80
vhostHTTPSPort = 443
KCP协议支持
kcpBindPort = 7000
QUIC协议支持
quicBindPort = 7002
3. 启动FRP服务端
# 前台启动
./frps -c ./frps.toml
后台启动(推荐)
nohup ./frps -c ./frps.toml &> /dev/null &
使用systemd管理(生产环境推荐)
cat > /etc/systemd/system/frps.service <
三、FRP客户端配置示例
1. 基础TCP穿透配置(frpc.toml)
[common]
serverAddr = "yourvpsip"
serverPort = 7000
token = "yoursecuretoken"
[[proxies]]
name = "ssh"
type = "tcp"
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000
2. HTTP/HTTPS穿透配置
[[proxies]]
name = "web"
type = "http"
localPort = 80
customDomains = ["yourdomain.com"]
[[proxies]]
name = "web-secure"
type = "https"
localPort = 443
customDomains = ["yourdomain.com"]
四、常见问题及解决方案
| 问题现象 |
可能原因 |
解决方案 |
| 连接失败 |
防火墙未开放端口 |
检查VPS安全组和iptables设置 |
| 端口冲突 |
端口被占用 |
使用netstat -tulnp检查并更换端口 |
| 权限不足 |
文件权限错误 |
执行chmod +x frps/frpc |
| 版本不匹配 |
客户端与服务端版本不一致 |
统一使用相同版本 |
| 速度慢 |
网络环境差 |
尝试启用KCP协议或优化配置 |
五、性能优化建议
- 协议选择:
- 普通TCP:稳定性优先
- KCP协议:高延迟/丢包网络环境
- QUIC协议:低延迟需求场景
- 连接池优化:
transport.maxPoolCount = 20
transport.tcpMux = true
- TLS加密:
transport.tls.force = true
transport.tls.certFile = "fullchain.pem"
transport.tls.keyFile = "privkey.pem"
- 日志管理:
log.level = "info"
log.file = "/var/log/frps.log"
log.maxDays = 7
通过以上步骤,您可以在VPS上成功部署FRP实现内网穿透,并根据实际需求进行配置优化。FRP的强大功能和灵活性使其成为内网穿透的理想选择,适用于远程桌面、Web服务暴露、SSH访问等多种场景。
发表评论