前置条件:
公网服务器1台
可访问的域名一个
域名解析
假设你的域名是 test.com
将frp.test.com解析到你的公网服务器ip
将*.frp.test.com解析到frp.test.com
服务器下载frp
# 访问 GitHub 发布页下载最新版本# https://github.com/fatedier/frp/releases
# 下载示例(替换为最新版本)
wget https://github.com/fatedier/frp/releases/download/v0.52.3/frp_0.52.3_linux_amd64.tar.gz
# 解压
tar -zxvf frp_0.52.3_linux_amd64.tar.gz
cd frp_0.52.3_linux_amd64
创建/etc/frp/frps.ini
[common]
bind_port = 7000
dashboard_port = 7500
dashboard_user = user
dashboard_pwd = pwdxxxxx
token = tokenxxxxx
subdomain_host=*.frp.test.com
# http端口
vhost_http_port=9898
# 启用 HTTPS
vhost_https_port = 7443
# 特权模式配置
allow_ports = 10000-20000
max_pool_count = 1000
# 详细日志
log_file = /var/log/frps.log
log_level = info
log_max_days = 7
# TLS 配置
tls_only = false
创建systemd服务
创建/etc/systemd/system/frps.service
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/usr/local/bin/frps -c /etc/frp/frps.ini
ExecReload=/usr/local/bin/frps reload -c /etc/frp/frps.ini
[Install]
WantedBy=multi-user.target
安装和启动服务
# 复制文件到系统目录
sudo cp frps /usr/local/bin/
sudo mkdir -p /etc/frp
sudo cp frps.ini /etc/frp/
# 设置权限
sudo chmod 755 /usr/local/bin/frps
sudo chmod 644 /etc/frp/frps.ini
# 启动服务
sudo systemctl daemon-reload
sudo systemctl enable frps
sudo systemctl start frps
# 检查状态
sudo systemctl status frps
客户端配置:
[common]
server_addr = frp.test.com
server_port = 7000
token = tokenxxxxx
[[web01]]
type = http
local_ip = 127.0.0.1
local_port = 9898
custom_domains = pay.frp.test.com
# 高级配置
use_encryption = true
use_compression = true
[[web02]]
type = http
local_ip = 127.0.0.1
local_port = 8889
custom_domains = web.frp.test.com
nginx反向代理
server {
listen 80;
server_name *.frp.test.com;
location / {
proxy_pass http://127.0.0.1:9898; # 客户端服务端口 9898 是服务端配置文件配置的,注意端口放行
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}