安装
# FRP 安装与配置指南
## 官方项目地址
[FRP GitHub 项目](https://github.com/fatedier/frp)
## CentOS 安装脚本
### 下载
```sh
yum install -y wget && wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
# 解压
tar -xvf frp_0.38.0_linux_amd64.tar.gz
1
# 移动至 /usr/local
mkdir /usr/local/frp
mv frp_0.38.0_linux_amd64/* /usr/local/frp/
1
2
2
# 文件说明
frps.ini
: 服务端配置文件frps
: 服务端软件frpc.ini
: 客户端配置文件frpc
: 客户端软件
# 配置 systemctl 来控制服务端运行
# 安装 vim(如果未安装)
yum -y install vim*
1
# 新建文件并写入配置内容
vim /usr/lib/systemd/system/frp.service
1
# 写入以下内容(注意路径)
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=simple
ExecStart=/usr/local/frp/frps -c /usr/local/frp/frps.ini
KillSignal=SIGQUIT
TimeoutStopSec=5
KillMode=process
PrivateTmp=true
StandardOutput=syslog
StandardError=inherit
[Install]
WantedBy=multi-user.target
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 重新加载服务的配置文件
systemctl daemon-reload
1
# 使用 systemctl 控制 frp
systemctl start frp
systemctl stop frp
systemctl restart frp
systemctl status frp
systemctl enable frp
systemctl disable frp
1
2
3
4
5
6
2
3
4
5
6
# 配置和使用
# 服务端 frps.ini
[common]
bind_port = 7000
vhost_http_port = 7071
dashboard_port = 7500
subdomain_host = dev.msh.com
1
2
3
4
5
2
3
4
5
# 启动 frp 服务端
systemctl start frp && systemctl status frp
1
# Nginx 反向代理配置
# 修改 nginx.conf
文件
server {
listen 80;
server_name *.dev.msh.com dev.msh.com;
location / {
proxy_pass http://127.0.0.1:7071;
proxy_set_header Host $host:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 7d;
proxy_send_timeout 7d;
proxy_read_timeout 7d;
}
# 防止爬虫抓取
if ($http_user_agent ~* "360Spider|JikeSpider|Spider|spider|bot|Bot|2345Explorer|curl|wget|webZIP|qihoobot|Baiduspider|Googlebot|Googlebot-Mobile|Googlebot-Image|Mediapartners-Google|Adsbot-Google|Feedfetcher-Google|Yahoo! Slurp|Yahoo! Slurp China|YoudaoBot|Sosospider|Sogou spider|Sogou web spider|MSNBot|ia_archiver|Tomato Bot|NSPlayer|bingbot") {
return 403;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 让 Nginx 重新加载配置文件
nginx -s reload
1
# 开启防火墙端口
# 开启防火墙端口(若已开启可忽略)
firewall-cmd --zone=public --add-port=7000/tcp --permanent
firewall-cmd --zone=public --add-port=7071/tcp --permanent
1
2
2
# 重启防火墙使修改生效
firewall-cmd --reload
1
# 客户端安装配置
# frpc.ini
文件
[common]
server_addr = 132.232.64.79
server_port = 7000
[http-a]
type = http
local_port = 8585
subdomain = a
[http-b]
type = http
local_port = 8686
subdomain = b
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
# 客户端 Windows
# 在 frp 解压目录下右键打开 PowerShell 或 cmd,执行如下命令
./frpc.exe -c .\frpc.ini
1
# 或者
frpc.exe -c frpc.ini
1
# 利用脚本一键开启隐藏 CMD 窗口
# 创建 frpc.bat
文件
- 在 FRP 解压目录下新建一个文本文件,并将其重命名为
frpc.bat
。 - 编辑该文件,粘贴以下内容并保存。
@echo off
if "%1" == "h" goto begin
mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:begin
REM
cd /d %~dp0
frpc -c frpc.ini
exit
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
# 解释
@echo off
:关闭批处理文件的命令回显。if "%1" == "h" goto begin
:检查第一个参数是否为h
,如果是,则跳转到begin
标签。mshta vbscript:createobject("wscript.shell").run("""%~nx0"" h",0)(window.close)&&exit
:使用mshta
启动一个隐藏的命令提示符窗口,并传递h
参数以再次调用自身。:begin
:定义一个标签,用于跳转。cd /d %~dp0
:切换到批处理文件所在的目录。frpc -c frpc.ini
:运行frpc
客户端并指定配置文件frpc.ini
。exit
:退出批处理文件。
# 使用方法
- 将
frpc.bat
文件放置在frpc.exe
和frpc.ini
所在的目录中。 - 双击
frpc.bat
文件,即可启动frpc
客户端,并且命令提示符窗口会隐藏。
# 创建 stop_frpc.bat
文件
- 在 FRP 解压目录下新建一个文本文件,并将其重命名为
stop_frpc.bat
。 - 编辑该文件,粘贴以下内容并保存。
@echo off
REM 查找并终止 frpc.exe 进程
taskkill /F /IM frpc.exe
exit
1
2
3
4
2
3
4
# 解释
@echo off
:关闭批处理文件的命令回显。taskkill /F /IM frpc.exe
:强制终止名为frpc.exe
的进程。exit
:退出批处理文件。
# 使用方法
- 将
stop_frpc.bat
文件放置在frpc.exe
所在的目录中,或者你可以将其放置在任何地方,只要你知道如何访问它即可。 - 双击
stop_frpc.bat
文件,即可关闭正在运行的frpc
客户端。
这样,你就可以通过双击 stop_frpc.bat
文件来关闭 FRP Windows 客户端。如果有任何问题或需要进一步的帮助,请随时提问。
在线编辑 (opens new window)
上次更新: 2025/02/25, 18:30:54