我的日常开发记录日志
首页
  • Laravel
  • Thinkphp
  • Swoole
  • Workman
  • php
  • HTML
  • CSS
  • JavaScript
  • Vue
  • ES6
  • 小程序
  • Mysql
  • Redis
  • Es
  • MongoDb
  • Git
  • Composer
  • Linux
  • Nginx
  • Docker
  • Vpn
  • 开发实战
  • 开发工具类
  • 友情链接
💖关于
💻收藏
  • 分类
  • 标签
  • 归档数据
GitHub (opens new window)

我的日常开发记录日志

never give up
首页
  • Laravel
  • Thinkphp
  • Swoole
  • Workman
  • php
  • HTML
  • CSS
  • JavaScript
  • Vue
  • ES6
  • 小程序
  • Mysql
  • Redis
  • Es
  • MongoDb
  • Git
  • Composer
  • Linux
  • Nginx
  • Docker
  • Vpn
  • 开发实战
  • 开发工具类
  • 友情链接
💖关于
💻收藏
  • 分类
  • 标签
  • 归档数据
GitHub (opens new window)
  • git

  • composer

  • linux

  • nginx

  • docker

  • vpn

  • frp

    • 安装
      • 配置和使用
        • 服务端 frps.ini
        • 启动 frp 服务端
      • Nginx 反向代理配置
        • 修改 nginx.conf 文件
        • 让 Nginx 重新加载配置文件
      • 开启防火墙端口
        • 开启防火墙端口(若已开启可忽略)
        • 重启防火墙使修改生效
      • 客户端安装配置
        • frpc.ini 文件
        • 客户端 Windows
        • 利用脚本一键开启隐藏 CMD 窗口
        • 创建 frpc.bat 文件
        • 解释
        • 使用方法
        • 创建 stop_frpc.bat 文件
        • 解释
        • 使用方法
    • ssl访问
    • linux上安装frp客户端
  • 脚本

  • 硬件

  • 运维
  • frp
窝窝侠
2024-06-15

安装

# 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

# 解压

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

# 文件说明

  • 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

# 重新加载服务的配置文件

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

# 配置和使用

# 服务端 frps.ini

[common]
bind_port = 7000
vhost_http_port = 7071
dashboard_port = 7500
subdomain_host = dev.msh.com
1
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

# 让 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

# 重启防火墙使修改生效

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

# 客户端 Windows

# 在 frp 解压目录下右键打开 PowerShell 或 cmd,执行如下命令

./frpc.exe -c .\frpc.ini
1

# 或者

frpc.exe -c frpc.ini
1

# 利用脚本一键开启隐藏 CMD 窗口

# 创建 frpc.bat 文件

  1. 在 FRP 解压目录下新建一个文本文件,并将其重命名为 frpc.bat。
  2. 编辑该文件,粘贴以下内容并保存。
@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

# 解释

  • @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:退出批处理文件。

# 使用方法

  1. 将 frpc.bat 文件放置在 frpc.exe 和 frpc.ini 所在的目录中。
  2. 双击 frpc.bat 文件,即可启动 frpc 客户端,并且命令提示符窗口会隐藏。

# 创建 stop_frpc.bat 文件

  1. 在 FRP 解压目录下新建一个文本文件,并将其重命名为 stop_frpc.bat。
  2. 编辑该文件,粘贴以下内容并保存。
@echo off
REM 查找并终止 frpc.exe 进程
taskkill /F /IM frpc.exe
exit
1
2
3
4

# 解释

  • @echo off:关闭批处理文件的命令回显。
  • taskkill /F /IM frpc.exe:强制终止名为 frpc.exe 的进程。
  • exit:退出批处理文件。

# 使用方法

  1. 将 stop_frpc.bat 文件放置在 frpc.exe 所在的目录中,或者你可以将其放置在任何地方,只要你知道如何访问它即可。
  2. 双击 stop_frpc.bat 文件,即可关闭正在运行的 frpc 客户端。

这样,你就可以通过双击 stop_frpc.bat 文件来关闭 FRP Windows 客户端。如果有任何问题或需要进一步的帮助,请随时提问。

在线编辑 (opens new window)
上次更新: 2025/02/25, 18:30:54
Centos7 搭建PPTP-VPN 服务
ssl访问

← Centos7 搭建PPTP-VPN 服务 ssl访问→

最近更新
01
showprocess用法
04-29
02
vue3中尖括号和冒号的使用细则
04-29
03
sd使用
02-22
更多文章>
🖥️

© 2025窝窝侠 💌 豫ICP备20005263号-2 🛀 Theme by 💝 Vdoing && 小胖墩er

  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×