Skip to content

FRP

说明

基础信息

启动

直接启动

Linux, Windows, Mac 均相同

shell
# 启动服务端
nohup ./frps -c ./frps.toml &
# 启动客户端
nohup ./frps -c ./frps.toml &

注册为系统服务启动

  • 作为服务端,配置如下
shell
# vim /etc/systemd/system/frps.service

[Unit]
# 服务名称,可自定义
Description = frp server
After = network.target syslog.target
Wants = network.target

[Service]
Type = simple
# 启动frps的命令,需修改为您的frps的安装路径
ExecStart = /path/to/frps -c /path/to/frps.toml
Restart = on-failure
RestartSec = 5s
StartLimitIntervalSec = 0

[Install]
WantedBy = multi-user.target

# 重新加载: systemctl daemon-reload
  • 作为客户端,service 名称应当为 frpc, 启动命令修正一下即可
  • 后续就可用 systemctl 进行管理了

Server服务端配置

toml
# frp 端口
bindPort = 7000
# 指定 HTTP 请求的监听端口
vhostHTTPPort = 7080
# 无需配置其他端口,在 client 注册上来时,会自动开启相关端口

Client

配置 http 站点

toml
serverAddr = "xxx.xxx.xxx.xxx"
serverPort = 7000

[[proxies]]
# 名称
name = "web"
# 协议
type = "http"
# 本地端口
localPort = 8080
# 此处,可以是其他局域网IP, 缺省是本地
localIP = "127.0.0.1"
# 接受的域名
customDomains = ["www.example.com"]

配置 ssh

toml
serverAddr = "x.x.x.x"
serverPort = 7000

[[proxies]]
name = "ssh"
type = "tcp"
# 此处,可以是其他局域网IP, 缺省是本地
localIP = "127.0.0.1"
localPort = 22
remotePort = 6000

配置 RDP

toml

[[proxies]]
name = "rdp"
type = "tcp"
# 此处,可以是其他局域网IP, 缺省是本地
localIP = "127.0.0.1"
localPort = 3389
remotePort = 3389

其他补充

注册为服务后的 frp 操作命令

shell
# 启动frp
systemctl start frps
# 停止frp
systemctl stop frps
# 重启frp
systemctl restart frps
# 查看frp状态
systemctl status frps
# 自启动
systemctl enable frps

server 端 nginx 配置示例。

server {
    listen 80;
    server_name www.example.com;

    location / {
        proxy_pass http://127.0.0.1:7080;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Released under the MIT License.