尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

frp 如何把 INI 配置迁移到 TOML、YAML 或 JSON 格式

frp 如何把 INI 配置迁移到 TOML、YAML 或 JSON 格式 frp 如何把 INI 配置迁移到 TOML、YAML 或 JSON 格式【免费下载链接】frpA fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.项目地址: https://gitcode.com/GitHub_Trending/fr/frpfrp 从 v0.52.0 起支持 TOML、YAML 和 JSON 三种配置格式INI 配置已被标记为弃用deprecated并计划在未来版本中移除新特性也只会出现在新格式中。如果你手里的 frpc 或 frps 还在用frpc.ini这类 INI 配置文件目标就是把它们改写成 TOML或 YAML、JSON让进程按新格式解析启动不再输出 INI 弃用警告。为什么迁移后文件会被识别成哪种格式frp 的配置加载逻辑在 pkg/config/load.go 中迁移前先弄清它的判断规则否则会踩坑先看内容不看扩展名。只要文件内容能按 INI 解析、且包含[common]段就被判定为 legacy INI 格式DetectLegacyINIFormat。也就是说把frpc.ini直接改名为frpc.toml而内容不改frp 仍然按 INI 解析还会继续打印警告。非 INI 内容会依次按 TOML → JSON → YAML 解析文件扩展名.toml、.yaml/.yml、.json只用来提供更准确的报错行号提示detectFormatFromPath。因此迁移的正确动作是改写配置内容本身并把文件保存为对应扩展名。迁移前提一个现有的 frpc 或 frps INI 配置文件例如仓库中的完整示例 conf/legacy/frpc_legacy_full.ini 和 conf/legacy/frps_legacy_full.ini。对照目标格式仓库提供了可直接参考的新格式文件conf/frpc_full_example.toml、conf/frps_full_example.toml以及最小示例 conf/frpc.toml、conf/frps.toml。注意完整示例文件开头注明了 This configuration file is for reference only不要直接拿它运行。弃用状态可查 doc/deprecations.mdINI 格式的 Replacement 明确为 YAML / JSON / TOML移除时间Removal target为 TBD。INI 和新格式的字段名不同INI 用蛇形命名server_addr新格式用驼峰或带点分组serverAddr、transport.poolCount。下面以客户端为例给出主要映射。frpc 客户端字段映射INI → TOML/YAML/JSON以下对照来自 conf/legacy/frpc_legacy_full.ini 与 conf/frpc_full_example.toml 两个官方示例文件INI[common]段TOML/YAML/JSONserver_addrserverAddrserver_portserverPortuseruserlog_filelog.tolog_levellog.levellog_max_dayslog.maxDaystokenauth.token配auth.method tokenoidc_*auth.oidc.*admin_addr/admin_port/admin_user/admin_pwdwebServer.addr/webServer.port/webServer.user/webServer.passwordpprof_enablewebServer.pprofEnabledial_server_timeouttransport.dialServerTimeoutpool_counttransport.poolCounttcp_mux/tcp_mux_keepalive_intervaltransport.tcpMux/transport.tcpMuxKeepaliveIntervalprotocoltransport.protocolhttp_proxytransport.proxyURLconnect_server_local_iptransport.connectServerLocalIPquic_*transport.quic.*tls_enabletransport.tls.enabletls_cert_file/tls_key_file/tls_trusted_ca_file/tls_server_nametransport.tls.certFile/keyFile/trustedCaFile/serverNamedisable_custom_tls_first_bytetransport.tls.disableCustomTLSFirstByteheartbeat_interval/heartbeat_timeouttransport.heartbeatInterval/transport.heartbeatTimeoutudp_packet_sizeudpPacketSizemeta_var1metadatas.var1includesincludes新格式中是数组如[./confd/*.toml]代理段INI 中形如[ssh]的段在新格式中统一为[[proxies]]数组项段名变成name字段常用字段对照INI代理段内TOML/YAML/JSON段名[ssh]name sshtypetypelocal_ip/local_port/remote_portlocalIP/localPort/remotePortbandwidth_limit/bandwidth_limit_modetransport.bandwidthLimit/transport.bandwidthLimitModeuse_encryption/use_compressiontransport.useEncryption/transport.useCompressiongroup/group_keyloadBalancer.group/loadBalancer.groupKeyhealth_check_type/health_check_interval_s/health_check_max_failed/health_check_timeout_shealthCheck.type/intervalSeconds/maxFailed/timeoutSecondshealth_check_urlhttp 健康检查路径healthCheck.pathsubdomain/custom_domainssubdomain/customDomains数组locationslocations数组http_user/http_pwdhttpUser/httpPasswordheader_X-From-WhererequestHeaders.set.x-from-wherehost_header_rewritehostHeaderRewriteproxy_protocol_versiontransport.proxyProtocolVersionmeta_var1metadatas.var1plugin xxxplugin_xxx yyy[proxies.plugin]表type xxx插件参数直接平铺完整的字段包括 visitor、stcp/xtcp/sudp、端口范围段等逐个对照 conf/frpc_full_example.toml 的注释即可它和 conf/legacy/frpc_legacy_full.ini 是同一份配置在新旧两种格式下的版本。改写一个最小 frpc 配置以仓库最小示例 conf/frpc.toml 对应的 INI 写法server_addr/server_port 一个[test-tcp]代理段为例TOML 结果为serverAddr 127.0.0.1 serverPort 7000 [[proxies]] name test-tcp type tcp localIP 127.0.0.1 localPort 22 remotePort 6000把同样的字段写成 YAML 或 JSON 时字段名完全一致只换语法。以下两段是由上面 TOML 等价改写出的示例serverAddr: 127.0.0.1 serverPort: 7000 proxies: - name: test-tcp type: tcp localIP: 127.0.0.1 localPort: 22 remotePort: 6000{ serverAddr: 127.0.0.1, serverPort: 7000, proxies: [ { name: test-tcp, type: tcp, localIP: 127.0.0.1, localPort: 22, remotePort: 6000 } ] }三种格式任选其一把文件分别保存为frpc.toml、frpc.yaml或frpc.json即可。frps 服务端迁移服务端的映射规则与客户端一致蛇形改驼峰/点分组。最小服务端配置对应 conf/frps.tomlbindPort 7000其余字段kcpBindPort、quicBindPort、vhostHTTPPort、vhostHTTPSPort、webServer.*、transport.*等逐行对照 conf/frps_full_example.toml 与 conf/legacy/frps_legacy_full.ini 完成替换。启动并验证迁移结果迁移后用新文件启动frpc 的-c参数默认值是./frpc.ini所以要显式传入新路径./frps -c ./frps.toml ./frpc -c ./frpc.toml验证有三条依据均来自动态加载与启动代码INI 警告消失。使用 legacy INI 启动时frpc 和 frps 都会打印固定警告见 cmd/frpc/sub/root.go 与 cmd/frps/root.goWARNING: ini format is deprecated and the support will be removed in the future, please use yaml/json/toml format instead!换成新格式后这条警告不再出现如果还在出现说明内容仍含[common]段被判定成了 INI。正常启动日志。frps 启动成功后输出frps started successfullyfrpc 输出start frpc service for config file [xxx] with aggregated configuration随后按配置建立到服务端的连接。严格模式帮你抓错别字。frpc 和 frps 的--strict_config参数默认都是 true未知字段会直接报错而不是静默忽略。这正适合迁移场景映射表里写错的字段名会在启动时立刻暴露出来。限制与注意事项新格式不支持 INI 的includes用*.ini扩展引用旧文件新格式的includes加载的是 TOML/YAML/JSON 文件见 pkg/config/load.go 中LoadAdditionalClientConfigs的注释 support yaml/json/toml配套引用的配置文件也要一并转换。INI 的移除时间目前是 TBD不是随下一个版本删除但既然新特性只加在新格式上建议尽早迁移。配置模板渲染环境变量替换、parseNumberRange等对非 INI 格式同样生效这部分行为不变。字段拿不准时把 conf/legacy/frpc_legacy_full.ini 与 conf/frpc_full_example.toml 并排看一遍两个文件覆盖同一套完整配置逐段对照就能补全上表没列到的项。【免费下载链接】frpA fast reverse proxy to help you expose a local server behind a NAT or firewall to the internet.项目地址: https://gitcode.com/GitHub_Trending/fr/frp创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表