剪藏#剪藏#码小帅

告别复杂配置!FRP+Nginx强强联合,一键实现内网HTTP、HTTPS穿透

2025 年 9 月 23 日1 分钟
分享Twitter / XTelegram微博

温馨提示

本文以frps为重点,不再陈述Nginx安装配置步骤

使用的frps版本为 0.64.0

安装方式为宿主机安装

服务器为腾讯云轻量服务器

需要自己准备备案域名

HTTPS在Nginx中配置。故此无需额外配置frps.toml文件

Notion image

Notion image

Notion image

Notion image

内网穿透

简单了解

内网穿透是一种技术,能够使具有特定源 IP 地址和源端口号的数据包不被 NAT 设备屏蔽,从而正确路由到内网主机。NAT 是一种将私有(保留)地址转化为合法IP地址的转换技术,它被广泛应用于各种类型 Internet 接入方式和各种类型的网络中。

以上仅供参考,建议咨询专业人员以获得更全面准确的信息。

Notion image

Notion image

Notion image

Notion image

内网穿透场景列举

Notion image

Notion image

远程办公:员工需要访问公司内网的资源,如文件同步、ERP系统、财务软件、数据库、FTP等。

网络游戏:网络游戏或者局域网单机游戏,需要和远程玩家之间进行对战。

远程控制:有些设备或机器需要通过内网连接,例如摄像头、NAS存储、智能家居等

远程调试:开发需要远程调试内网中的应用程序,而应用程序可能位于内网中,因此需要通过内网穿透来实现远程调试

内部测试:内部测试需要访问内网中的测试环境,而测试环境可能位于内网中,因此需要通过内网穿透来实现内部测试

Notion image

Notion image

frp是什么

frp 是一款高性能的反向代理应用,专注于内网穿透。它支持多种协议,包括 TCP、UDP、HTTP、HTTPS 等,并且具备 P2P 通信功能。使用 frp,您可以安全、便捷地将内网服务暴露到公网,通过拥有公网 IP 的节点进行中转。

来源:https://gofrp.org/zh-cn/docs/overview/

Notion image

Notion image

Notion image

Notion image

下载最新版0.64.0

Notion image

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

Notion image

解压文件

Notion image

tar -zcvf frp_0.64.0_linux_amd64.tar.gz

按照自己的需求。放在指定目录中

Notion image

配置Frps启动服务

Notion image

1.创建 frps.service 文件

vim /etc/systemd/system/frps.service

2.配置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

[Install]

WantedBy = multi-user.target

3.使用 systemd 命令管理 frps 服务

启动frp

sudo systemctl start frps

停止frp

sudo systemctl stop frps

重启frp

sudo systemctl restart frps

查看frp状态

sudo systemctl status frps

4.设置 frps 开机自启动

sudo systemctl enable frps

Notion image

配置frps.toml配置文件内容

Notion image

bindAddr = "0.0.0.0" # 服务绑定的IP

bindPort = 7000 #frps服务端口

vhostHTTPPort = 7777 #http服务端口 默认80 占用自行更换

auth.method = "token" #认证方式

auth.token = "" #认证方式对应的token

[webServer]

addr = "0.0.0.0" # 控制台绑定的IP

port = 7500 # 控制台服务端口

user = "" #控制台访问用户名

password = "" #控制台访问密码

Notion image

启动frp服务端

Notion image

sudo systemctl start frps

使用 systemctl status frps 查看启动是否成功。如下代码所示。即为启动成功

JAVASCRIPT
● frps.service - Frp Server
   Loaded: loaded (/etc/systemd/system/frps.service; enabled; vendor preset: disabled)
   Activeactive (running) since Thu 2025-09-18 10:52:54 CST; 12min ago
 Main PID: 12560 (frps)
   CGroup: /system.slice/frps.service
           └─12560 /home/frps/frps -c /home/frps/frps.toml
 
Sep 18 10:52:54 VM-8-13-centos systemd[1]: Started Frp Server.
Sep 18 10:52:54 VM-8-13-centos frps[12560]: 2025-09-18 10:52:54.725 [I] [frps/root.go:108] frps uses config file: /home/frps/frps.toml
Sep 18 10:52:54 VM-8-13-centos frps[12560]: 2025-09-18 10:52:54.814 [I] [server/service.go:237] frps tcp listen on 0.0.0.0:7000
Sep 18 10:52:54 VM-8-13-centos frps[12560]: 2025-09-18 10:52:54.814 [I] [server/service.go:305] http service listen on 0.0.0.0:7777
Sep 18 10:52:54 VM-8-13-centos frps[12560]: 2025-09-18 10:52:54.814 [I] [server/service.go:319] https service listen on 0.0.0.0:7443
Sep 18 10:52:54 VM-8-13-centos frps[12560]: 2025-09-18 10:52:54.814 [I] [frps/root.go:117] frps started successfully
Sep 18 10:52:54 VM-8-13-centos frps[12560]: 2025-09-18 10:52:54.814 [I] [server/service.go:351] dashboard listen on 0.0.0.0:7500
Hint: Some lines were ellipsized, use -l to show in full.

Notion image

下载Window客户端

Notion image

frp_0.64.0_windows_amd64.zip 自行解压

Notion image

配置客户端文件frpc.toml

Notion image

serverAddr = "" #frps服务端IP

serverPort = 7000 #frps服务端端口

auth.method = "" #frps服务端认证类型

auth.token = "" #frps服务端认证类型的令牌

[[proxies]]

name = "test-http" #代理的本地服务名称 自定义

type = "http" #代理的类型支持:tcp, udp, http, https, tcpmux, stcp, sudp, xtcp

localIP = "127.0.0.1" #代理的本地IP

localPort = 8080 #代理的本地端口

Notion image

启动客户端

Notion image

frpc.exe -c /path/to/frc.toml

Notion image

HTTP、HTTPS配置

Notion image

只需要配置Nginx即可

JAVASCRIPT
server {
listen 80
server_name 你的域名; 
 #重点http跳转https
     rewrite ^(.*) https://$server_name$1 permanent;
server_tokens off;
 
}
server {
 #SSL 访问端口号为 443
listen 443 ssl; 
 #填写绑定证书的域名
server_name 你的域名; 
 #证书文件名称
ssl_certificate 你的证书文件目录; 
 #私钥文件名称
ssl_certificate_key 你的证书文件目录; 
ssl_session_timeout 5m;
 #请按照以下协议配置
ssl_protocols TLSv1 TLSv1.1 TLSv1.2
 #请按照以下套件配置,配置加密套件,写法遵循 openssl 标准。
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE
ssl_prefer_server_ciphers on;
 #让http请求重定向到https请求 
error_page 497  https://$host$uri?$args;  

location / {
  proxy_pass   http://127.0.0.1:7777;#frps的http协议的端口号
  proxy_set_header   Host    $host:$server_port;  
  proxy_set_header   X-Real-IP   $remote_addr;  
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_hide_header   X-Powered-By;
}
server_tokens off;
}

Notion image

Notion image

大功告成

Notion image

接下来浏览器直接访问即可~

END

Notion image

原文地址: https://mp.weixin.qq.com/s?__biz=MzAxODAyMTU3Mg==&mid=2649876378&idx=1&sn=d0def8296b20ab924a378710705ece52&chksm=82d17207f0b6ce9feb970cf1dfeed9301401bcac1ddeda5de87e1c25d95517c3a4206bff901e&mpshare=1&scene=1&srcid=0923dSGgRrJPsgoSBakl4wUW&sharer_shareinfo=323b9a4c40c4f5fb6685ebdeb2608c96&sharer_shareinfo_first=323b9a4c40c4f5fb6685ebdeb2608c96#rd

相关文章