2026/4/18 8:06:57
网站建设
项目流程
无限弹窗网站链接怎么做,怎么联系地推公司,建设电子商务网站流程图,坪山网站建设行情使用 frp 实现内网穿透#xff1a;让本地服务器安全暴露到公网
frp#xff08;frp 是 Fast Reverse Proxy 的缩写#xff09;是一个轻量、高效的内网穿透工具#xff0c;可以将内网的 SSH、Web、MySQL 等服务安全地暴露到公网。本文基于一个实际生产环境#xff0c;介绍 …使用 frp 实现内网穿透让本地服务器安全暴露到公网frpfrp 是 Fast Reverse Proxy 的缩写是一个轻量、高效的内网穿透工具可以将内网的 SSH、Web、MySQL 等服务安全地暴露到公网。本文基于一个实际生产环境介绍 frp 的安装、配置和使用方法实现通过域名访问本地服务器的 Web 服务通过公网 SSH 端口访问本地服务器的 SSH可选通过公网访问 MySQL整个方案紧凑、安全只需一台有公网 IP 的云服务器作为 frps 服务端。网络拓扑图云服务器 B 拥有公网 IP运行 frps 和 Nginx本地服务器 AA 通过 VPN 能访问云服务器 B 的内网 IP运行 frpcVPN 内用户也可通过云服务器B内网IP:2201直接 SSH 到本地 AA无需知道 AA 内网 IP1. 安装 frp前往 frp GitHub Releases 下载最新版本推荐 amd64 或 arm64。服务端云服务器 B# 创建目录mkdir-p /opt/frpcd/opt/frp# 下载按你的 CPU 架构选择wgethttps://github.com/fatedier/frp/releases/download/v0.66.0/frp_0.66.0_linux_amd64.tar.gztarzxvf frp_0.66.0_linux_amd64.tar.gzcdfrp_0.66.0_linux_amd64# 拷贝二进制cpfrps /usr/local/bin/chmodx /usr/local/bin/frps客户端本地服务器 AAmkdir-p /opt/frpcd/opt/frpwgethttps://github.com/fatedier/frp/releases/download/v0.66.0/frp_0.66.0_linux_amd64.tar.gztarzxvf frp_0.66.0_linux_amd64.tar.gzcpfrp_0.66.0_linux_amd64/frpc /usr/local/bin/chmodx /usr/local/bin/frpc建议使用 systemd 服务开机自启略可自行搜索 “frp systemd”。2. 服务端配置云服务器 B/etc/frp/frps.tomlbindPort 37001 # frpc 连接 frps 的端口内网安全 bindAddr 0.0.0.0 vhostHTTPPort 31080 # HTTP 穿透虚拟主机端口 # Dashboard可选监控用 webServer.addr 0.0.0.0 webServer.port 37501 webServer.user frp_topka webServer.password xxxx # 必须开启鉴权 auth.method token auth.token xxxx # 自定义强令牌 log.to /var/log/frps.log log.level info log.maxDays 7systemd 服务服务端vim/etc/systemd/system/frps.service[Unit] DescriptionFRP Server Afternetwork.target [Service] Typesimple ExecStart/usr/local/bin/frps -c /etc/frp/frps.toml Restartalways RestartSec5 [Install] WantedBymulti-user.target启动systemctl daemon-reload systemctlenablefrps systemctl start frps systemctl status frps3. Nginx 配置云服务器 B反向代理 frp HTTP 端口server { listen 80; server_name *.kong.xxx.cn kong.xxx.cn; # IP 白名单 #allow 1.2.3.4; #allow 5.6.7.0/24; #deny all; location / { proxy_pass http://127.0.0.1:31080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }重启 Nginx 即可。域名已解析到云服务器 B 的公网 IP。4. 客户端配置本地服务器 AA/etc/frp/frpc.tomlserverAddr 192.168.1.13 # 云服务器 B 的内网 IP serverPort 37001 auth.method token auth.token xxxx # 与服务端一致 # SSH 穿透 [[proxies]] name ubuntu type tcp localIP 127.0.0.1 localPort 22 remotePort 2201 # 公网访问公网IP:2201 → 本地SSH # Web 穿透 [[proxies]] name admin_workstation type http localIP 127.0.0.1 localPort 80 customDomains [kong.xxx.cn] # MySQL 穿透可选 [[proxies]] name mysql type tcp localIP 127.0.0.1 localPort 3306 remotePort 13306systemd 服务客户端vim/etc/systemd/system/frpc.service[Unit] DescriptionFRP Client Afternetwork.target [Service] Typesimple ExecStart/usr/local/bin/frpc -c /etc/frp/frpc.toml Restartalways RestartSec5 [Install] WantedBymulti-user.target启动systemctl daemon-reload systemctlenablefrpc systemctl start frpc systemctl status frpc5. 使用方式Web 服务直接访问http://kong.xxx.cn或子域名即可访问本地 AA 的 Web 服务SSH 访问本地 AA公网ssh user云服务器B公网IP -p 2201VPN 内ssh user192.168.1.13 -p 2201无需知道 AA 内网 IPMySQL连接云服务器B公网IP:13306管理面板访问云服务器B公网IP:37501用户名frp_topka密码自行设置安全建议令牌token设置复杂防火墙只开放必要端口80、2201、13306、37501 等可配合 Nginx 添加 IP 白名单或基本认证进一步加强安全定期查看 Dashboard 监控连接状态这样就完成了安全、稳定的内网穿透方案整个配置简单高效适合个人和小型团队使用。祝使用愉快