FRP(Fast Reverse Proxy) 的详细部署与应用教程

以下是基于 FRP(Fast Reverse Proxy) 的详细部署与应用教程,环境如下:

  • 服务器(Server):Linux(如 Ubuntu 20.04)

  • 客户端(Client)1:Windows

  • 客户端(Client)2:Linux(如 Ubuntu)


🧩 一、FRP 简介

FRP 是一个高性能的反向代理应用,可以用于:

  • 内网穿透

  • 远程桌面连接(RDP / SSH)

  • 远程 Web 服务访问

  • 自定义 TCP/UDP 映射


📦 二、准备工作

1. 下载对应平台的 FRP 程序

访问:https://github.com/fatedier/frp/releases

下载最新版:

  • 服务器(Linux) ➜ frp_*.tar.gz 选择 linux_amd64

  • Windows 客户端 ➜ frp_*.zip 选择 windows_amd64

  • Linux 客户端 ➜ 同样 linux_amd64


🖥️ 三、Linux 服务器端配置(frps)

1. 解压并准备

wget https://github.com/fatedier/frp/releases/download/v0.58.0/frp_0.58.0_linux_amd64.tar.gz
tar -zxvf frp_0.58.0_linux_amd64.tar.gz
cd frp_0.58.0_linux_amd64

2. 编辑 frps.ini

[common]
bind_port = 7000             # 客户端连接使用的端口
dashboard_port = 7500        # 管理面板端口(可选)
dashboard_user = admin
dashboard_pwd = admin123
vhost_http_port = 8080       # HTTP 服务端口(用于 HTTP 代理)
vhost_https_port = 8443      # HTTPS 服务端口(可选)
token = your_secure_token    # 与客户端通信使用的 token,请设置强密码

3. 启动服务端

./frps -c ./frps.ini

或者创建 systemd 服务:

sudo cp frps /usr/local/bin/
sudo cp frps.ini /etc/frp/
sudo vim /etc/systemd/system/frps.service

内容如下:

[Unit]
Description=FRP Server
After=network.target

[Service]
ExecStart=/usr/local/bin/frps -c /etc/frp/frps.ini
Restart=on-failure

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reexec
sudo systemctl enable frps
sudo systemctl start frps

🧑‍💻 四、Windows 客户端配置(frpc)

1. 解压

解压 frp_0.58.0_windows_amd64.zip,进入目录。

2. 编辑 frpc.ini

示例:将本机的远程桌面 (RDP) 映射到服务器的 6000 端口

[common]
server_addr = x.x.x.x         # 服务器公网 IP
server_port = 7000
token = your_secure_token

[rdp]
type = tcp
local_ip = 127.0.0.1
local_port = 3389             # 本机 RDP 端口
remote_port = 6000            # 服务端开放端口,访问 x.x.x.x:6000 即远程桌面

也可以设置 HTTP 服务:

[web]
type = http
local_port = 80
custom_domains = www.yourdomain.com

3. 启动客户端

双击运行:

frpc.exe -c frpc.ini

可以写个 run.bat

@echo off
frpc.exe -c frpc.ini
pause

🐧 五、Linux 客户端配置(frpc)

1. 解压并进入目录

tar -zxvf frp_0.58.0_linux_amd64.tar.gz
cd frp_0.58.0_linux_amd64

2. 编辑 frpc.ini

[common]
server_addr = x.x.x.x
server_port = 7000
token = your_secure_token

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6001  # 远程访问服务器IP:6001 实现 SSH 登录内网客户端

3. 启动客户端

./frpc -c ./frpc.ini

或配置 systemd 服务,方法与服务端类似。


🌐 六、典型应用示例

📁 文件服务器 HTTP 暴露

[web_file]
type = http
local_port = 8080
custom_domains = files.yourdomain.com

要求服务端绑定好 vhost_http_port,并做好域名解析。

🖥️ RDP / SSH

  • Windows 远程桌面:

    • 客户端配置:映射 3389 → 服务端 6000

    • 使用:mstsc 输入:x.x.x.x:6000

  • Linux SSH:

    • 客户端配置:映射 22 → 服务端 6001

    • 使用:ssh user@x.x.x.x -p 6001


🔒 七、安全建议

  • 启用 token 验证(务必设置)

  • 使用 iptables 限制客户端 IP 段连接 frps 端口

  • 开启 HTTPS 时使用合法证书

  • 如公网服务器开启了防火墙,务必允许 bind_port 和相关 remote_port


✅ 总结

项目 服务端(frps) 客户端(frpc)
操作系统 Linux Windows / Linux
配置文件 frps.ini frpc.ini
启动命令 ./frps -c ./frpc -cfrpc.exe -c
服务端口 7000 自定义映射端口
用途示例 暴露 HTTP / RDP / SSH 将本地服务穿透到公网

 

© 版权声明
THE END
喜欢就支持一下吧
点赞12 分享