内网穿透 FRP 使用教程

1、最朴素模型:纯 TCP 直映射 = 一一对应

这种方式“端口一一对应”是对的。缺点是:

  • 多个服务时服务器要开很多端口
  • 用户访问要写端口号
  • 不方便接入 HTTPS/域名/统一鉴权
外部用户  -> 服务器IP:remote_port  -> frps -> frpc -> 本地localhost:local_port

例如:

[common]
server_addr = 你的服务器IP
server_port = 7000 #保持这个内网穿透服务跑建立 frpc→frps 的长连接,就是连接客户端和服务端
token = change_me_token
# 如需要,可开启控制连接 TLS(新版本选项)
# tls_enable = true

# 一对一映射:Vue 开发服务
[vue_dev_tcp]
type = tcp
local_ip = 127.0.0.1
local_port = 6666
remote_port = 16666 # 公网访问端口:服务器IP:16666

# 一对一映射:SSH
[ssh_tcp]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000 # 公网访问端口:服务器IP:6000

2、HTTP/HTTPS 场景

如果服务是http或者https的服务就用这种

因为http/https这两个有些特殊,原因是基于Host头来的

域名解析 → 入口端口接收 → 根据 Host 找对应隧道 → 走 frpc 转本地服务 → 回应原路返回。

例如

[common]
server_addr = your.server.ip.or.domain
server_port = 7000
token = change_me_token
# 可选:tls_enable = true (frp 0.5x+ 支持,控制连接加密)

# Vue Dev (端口 6666)
[vue_dev]
type = http
local_port = 6666
custom_domains = dev.example.com

# API 服务 (端口 7001)
[api_service]
type = http
local_port = 7001
custom_domains = api.example.com

# 管理后台 (端口 5173)
[admin_panel]
type = http
local_port = 5173
custom_domains = admin.example.com

# 如果你想用子域名模式,需要 frps.ini 中设置 subdomain_host
# 例如:
# [portal]
# type = http
# local_port = 8000
# subdomain = portal # 会变成 portal.your-subdomain-host