BTCPay Server 2.4.5 配置参数详解
BTCPay Server 2.4.5 的配置参数详解:实测命令行参数、settings.config 配置文件与 BTCPAY_/NBXPLORER_ 环境变量三层渠道的优先级、全量参数逐项说明与 Docker 部署环境变量生成机制。
BTCPay Server 2.4.5 配置参数详解
目标:讲清 BTCPay Server 2.4.5 全链路(主程序、NBXplorer 2.6.19、Bitcoin Core、PostgreSQL)的配置体系——命令行参数、
settings.config配置文件、BTCPAY_/NBXPLORER_环境变量三层渠道的优先级实测、全量参数逐项说明,以及 Docker Compose 部署形态下从BTCPAYGEN_*到容器环境变量的生成机制。全部参数与回显在 Ubuntu 22.04 服务器实测取得(原生 systemd 部署与官方 btcpayserver-docker 部署两种形态),链的验证环节采用 regtest 私有测试链。
一、环境信息
本文所有配置项均在以下环境实测,读者按相同版本操作可获得一致结果:
- 操作系统:Ubuntu 22.04(x86_64)
- BTCPay Server:2.4.5(官方镜像
btcpayserver/btcpayserver:2.4.5,内含 .NET Runtime 10.0.12) - NBXplorer:2.6.19(官方镜像
nicolasdorier/nbxplorer:2.6.19) - Bitcoin Core:31.1(官方栈镜像
btcpayserver/bitcoin:31.1-1) - PostgreSQL:18.6(官方栈镜像
btcpayserver/postgres:18.6) - 部署形态一:源码构建 + systemd 托管(安装过程见《Ubuntu 22.04 安装 BTCPay Server 2.4.5 指南》)
- 部署形态二:官方 btcpayserver-docker 一键脚本 + Docker Compose(部署过程见《BTCPay Server 2.4.5 Docker Compose 部署指南》)
- 实测网络:regtest 私有测试链(主网 mainnet 的参数差异在对应小节单独标注)
主程序与 NBXplorer 是同一套配置框架(StandardConfiguration)的两个宿主,因此两者支持完全相同的三层配置渠道与优先级规则,只是环境变量前缀不同(BTCPAY_ 与 NBXPLORER_)。
二、前置条件
本文是配置专题篇,不重复安装过程,但要求读者手里有一套能跑起来的环境:
- 一台 Ubuntu 22.04 服务器,具备 root 或 sudo 权限;
- 已按《Ubuntu 22.04 安装 BTCPay Server 2.4.5 指南》完成原生部署,或按《BTCPay Server 2.4.5 Docker Compose 部署指南》完成 Docker Compose 部署;
- PostgreSQL 已在运行(原生形态
systemctl is-active postgresql返回active;Compose 形态栈内自带); - 本文示例命令均为只读查看或短时启动验证,不改动线上数据;个别验证步骤会新建独立数据库(
btcpay_c1test等),验证后即删除。
三、参数查看与修改方式
3.1 三层配置渠道与生效优先级(实测)
BTCPay Server 与 NBXplorer 的每个参数都可以从三个渠道给出,取值优先级实测如下(从高到低):
- 命令行参数(如
--port=23102); - 配置文件(
<数据目录>/<网络>/settings.config中未注释的键); - 环境变量(前缀
BTCPAY_/NBXPLORER_)。
优先级验证过程(regtest,原生主程序二进制,逐一启动观察实际监听端口):先准备一份配置文件,写入 port=23101、network=regtest、bind=0.0.0.0 与独立的 PostgreSQL 连接串(库名 btcpay_c1test),然后分三次启动:
# 渠道一:仅配置文件(文件里 port=23101)
dotnet BTCPayServer.dll --nodefaultchain
# 实测日志:
info: Configuration: Data Directory: /test
info: Configuration: Configuration File: /test/Main/settings.config
info: Configuration: Network: Regtest
info: Configuration: Now listening on: http://0.0.0.0:23101
# 渠道二:命令行 --port=23102 覆盖文件的 23101
dotnet BTCPayServer.dll --nodefaultchain --port=23102
# 实测日志:
info: Configuration: Now listening on: http://0.0.0.0:23102
# 渠道三:环境变量 BTCPAY_PORT=23103 与命令行 --port=23102 同时给出
BTCPAY_PORT=23103 dotnet BTCPayServer.dll --nodefaultchain --port=23102
# 实测日志(命令行胜出):
info: Configuration: Now listening on: http://0.0.0.0:23102
# 渠道四:仅环境变量 BTCPAY_PORT=23103(文件仍是 23101)
BTCPAY_PORT=23103 dotnet BTCPayServer.dll --nodefaultchain
# 实测日志(配置文件胜出,环境变量落败):
info: Configuration: Now listening on: http://0.0.0.0:23101
再用另一个参数复核一次「文件 > 环境变量」:配置文件写 network=regtest,同时导出 BTCPAY_NETWORK=mainnet,启动日志显示:
info: Configuration: Network: Regtest
环境变量没有覆盖文件。NBXplorer 侧用同样方法复核(文件 port=24451 + 环境变量 NBXPLORER_PORT=24452):
info: Configuration: Configuration File: /test/Main/settings.config
info: Configuration: Now listening on: http://127.0.0.1:24451
结论一致:命令行 > 配置文件 > 环境变量。
⚠️ 注意:这个优先级与很多软件「环境变量覆盖文件」的直觉相反,是本组件最容易踩的坑——官方 Docker 部署完全靠环境变量传参,如果手工在
/datadir/<网络>/settings.config里把某个注释键(如#postgres=...)解除注释,该键会反向压过 Compose 给容器的BTCPAY_POSTGRES环境变量。
💡 技术拓展:BTCPay 支持 4 条 Bitcoin 网络参数口径,选择前先明确各自用途——
网络 说明 典型用途 mainnet 主网,真金白银 生产收款 testnet 公共测试网,币免费但需水龙头 联调 signet 签名测试网,需许可签名出块 稳定测试环境 regtest 本地私有链,自己出块,秒级确认 自动化验证 本文实验采用 regtest(秒出块、可重置),生产一律 mainnet;同一台机器切换网络只需改
network参数,但数据目录、cookie 文件随之按网络分目录隔离(见 3.2)。
3.2 配置文件位置
配置文件固定放在「数据目录/网络子目录/settings.config」,网络子目录名为 Main/TestNet/RegTest。两种部署形态的实测位置:
| 形态 | 组件 | 数据目录 | 配置文件实测路径 |
|---|---|---|---|
| 原生 systemd | BTCPay Server | /var/lib/btcpay(B1 部署用 --datadir=/var/lib/btcpay) | /var/lib/btcpay/RegTest/settings.config(mainnet 为 /var/lib/btcpay/Main/settings.config) |
| 原生 systemd | NBXplorer | /var/lib/nbxplorer | /var/lib/nbxplorer/RegTest/settings.config |
| Docker Compose | BTCPay Server | 数据卷挂载在 /datadir | /datadir/RegTest/settings.config |
| Docker Compose | NBXplorer | 数据卷挂载在 /datadir | /datadir/RegTest/settings.config |
两个依据:一是启动日志直接打印生效的配置文件路径(info: Configuration: Configuration File: /datadir/RegTest/settings.config);二是查看数据目录实测内容:
ls -la /datadir/ /datadir/RegTest/
实测回显(Docker Compose 形态主程序数据卷):
/datadir/:
-rw------- 1 root root 48589 Oct 23 02:26 btcpay20261023.log
drwxr-xr-x 3 root root 4096 Oct 23 02:26 LocalStorage
-rw------- 1 root root 940 Oct 23 02:26 key-4b2a1b1d-286c-4e1b-a062-42031f1b6a7b.xml
-rw------- 1 root root 1261 Oct 23 02:26 rates-cache.json
drwxr-xr-x 3 root root 4096 Oct 23 02:26 RegTest
drwxr-xr-x 2 root root 4096 Oct 23 02:26 tmp
/datadir/RegTest/:
-rw------- 1 root root 745 Oct 23 02:26 settings.config
💡 说明:
settings.config没有就自动按默认值创建模板(见 3.3);key-*.xml是数据保护密钥(用户凭据加密用),LocalStorage/是插件与界面本地存储,rates-cache.json是汇率缓存。不显式指定数据目录时,默认值为运行用户$HOME/.btcpayserver/<网络>(mainnet 全称$HOME/.btcpayserver/Main),主程序--help中--btcexplorercookiefile的默认值/var/lib/btcpay/.nbxplorer/Main/.cookie也印证了这种「数据目录 + 网络」的拼装规则。
3.3 配置文件模板(首次启动自动生成)
首次启动时若配置文件不存在,进程会自动生成一份全注释的模板(全部是默认值参考,不产生任何实际配置)。主程序在 regtest 下的实测模板全文:
### Global settings ###
#network=mainnet
### Server settings ###
#port=23002
#bind=127.0.0.1
#httpscertificatefilepath=devtest.pfx
#httpscertificatefilepassword=toto
#disablessrfprotection=false
#ssrfexceptions=nas.home.arpa:8080;10.8.0.0/24;[fd00::/8]:443
### Host integration ###
#btcpayhostenabled=false
#btcpayhostexecutable=btcpay-host
### Database ###
#postgres=User ID=root;Password=myPassword;Host=localhost;Port=5432;Database=myDataBase;
### NBXplorer settings ###
#BTC.explorer.url=http://127.0.0.1:24446/
#BTC.explorer.cookiefile=/root/.nbxplorer/RegTest/.cookie
#BTC.blockexplorerlink=https://mempool.space/tx/{0}
#BTC.lightning=/root/.lightning/lightning-rpc
#BTC.lightning=https://apitoken:API_TOKEN_SECRET@charge.example.com/
NBXplorer 在 regtest 下自动生成的模板更长(每个受支持链一段),BTC 段与文件尾部通用段实测如下(节选):
####Common Commands####
####If Bitcoin Core is running with default settings, you should not need to modify this file####
####All those options can be passed by through command like arguments (ie `-port=19382`)####
## This is the RPC Connection to your node
#btc.rpc.url=http://127.0.0.1:18443/
#By user name and password
#btc.rpc.user=bitcoinuser
#btc.rpc.password=bitcoinpassword
#By cookie file
#btc.rpc.cookiefile=yourbitcoinfolder/.cookie
#By raw authentication string
#btc.rpc.auth=walletuser:password
## This is the connection to your node through P2P
#btc.node.endpoint=127.0.0.1:BTC
## minutxovalue defines the minimum value allowed for a utxo to be tracked
#btc.minutxovalue=1
## startheight defines from which block you will start scanning, if -1 is set, it will use current blockchain height
#btc.startheight=-1
## rescan forces a rescan from startheight
#btc.rescan=0
## rescaniftimebefore only lets rescan occur if current unix timestamp (seconds) is less than the given value
## requires btc.rescan to be true
#btc.rescaniftimebefore=1635210000
## If more than 0, the size of the cache for the database, in MB. Else, no limit on the size of the cache. (default: 50)
#dbcache=50
## Disable cookie, local ip authorization (unsecured)
#noauth=0
## Add a server alias to be returned in status response
#instancename=my_business_nbxplorer
## Expose the node RPC through the REST API
#exposerpc=0
## What crypto currencies is supported
#chains=agm,btc,btx,ltc,doge,pepe,bch,grs,btg,dash,trc,polis,mona,ftc,ufo,via,xmcc,gbx,colx,chc,lbtc,qtum,html,mue
## Activate or disable verbose logs
#verbose=0
####Server Commands####
#port=24446
#bind=127.0.0.1
#regtest=1
模板里的注释即默认值文档:主程序 regtest 默认端口 23002、NBXplorer regtest 默认端口 24446;主网(mainnet)对应默认端口为 23000 与 24444(主程序 --help 中 --btcexplorerurl 的默认值 http://127.0.0.1:24444/ 即 NBXplorer 主网默认端口)。修改方式就是解除注释并赋值,重启进程生效。
3.4 通过 Web 界面查看与修改
除进程级配置外,还有一类「业务策略」参数在 Web 管理界面(服务器设置 / 商店设置)修改,落库到 PostgreSQL 而不是 settings.config:注册策略、邮件设置、汇率源、品牌外观、发票默认时限等。官方 btcpay-admin.sh 的 reset-server-policy 子命令直接删除 Settings 表中 Id = 'BTCPayServer.Services.PoliciesSettings' 的行,即这一层的存储位置佐证:
btcpay-admin.sh reset-server-policy
💡 说明:进程级参数(本篇 4~6 章)改配置文件/环境变量,业务策略参数改 Web 界面或调 Greenfield API,两层互不覆盖。业务策略的完整口径见商店与服务器设置页面的逐项说明,本篇不展开。
四、参数总览
4.1 BTCPay Server 全量命令行参数(--help 实测)
在主程序目录执行 dotnet BTCPayServer.dll --help 的完整实测输出(官方 Docker 镜像 2.4.5 内,/app 目录):
BTCPay
Open source, self-hosted payment processor.
Usage: BTCPay [options]
Options:
-? | -h | --help Show help information
-n | --network Set the network among (mainnet,testnet,regtest) (default: mainnet)
--testnet | -testnet Use testnet (deprecated, use --network instead)
--regtest | -regtest Use regtest (deprecated, use --network instead)
--signet | -signet Use signet (deprecated, use --network instead)
--chains | -c Chains to support as a comma separated. Default to empty if --nodefaultchain is set (default: btc; available: btc)
--nodefaultchain | -nodefaultchain Allow BTCPay to start without any chain enabled (default: false)
--postgres Connection string to a PostgreSQL database
--nocsp Disable CSP (default false)
--disablessrfprotection Disable outbound HTTP protection against DNS rebinding and private-network access (default: false)
--ssrfexceptions Comma- or semicolon-separated exact hostnames, IP addresses, and CIDR ranges allowed through SSRF protection, optionally restricted to a port (for example: nas.home.arpa:8080;10.8.0.0/24;[fd00::/8]:443). Exact hostnames trust all resolved addresses (default: empty)
--deprecated Allow deprecated settings (default:false)
--externalservices Links added to external services inside Server Settings / Services under the format service1:path2;service2:path2.(default: empty)
--btcpayhostenabled Enable the btcpay-host integration (default: false)
--btcpayhostexecutable Path to the btcpay-host executable (default: btcpay-host)
--rootpath The root path in the URL to access BTCPay (default: /)
--torrcfile Path to torrc file containing hidden services directories (default: empty)
--torservices Tor hostnames of available services added to Server Settings (and sets onion header for btcpay). Format: btcpayserver:host.onion:80;btc-p2p:host2.onion:81,BTC-RPC:host3.onion:82,UNKNOWN:host4.onion:83. (default: empty)
--socksendpoint Socks endpoint to connect to onion urls (default: empty)
--updateurl Url used for once a day new release version check. Check performed only if value is not empty (default: empty)
--debuglog A rolling log file for debug messages.
--debugloglevel The severity you log (default:information)
--disable-registration Disables new user registrations (default:true)
--recommended-plugins Deprecated. Accepted for compatibility but no longer used by the embedded plugin directory.
--xforwardedproto If specified, set X-Forwarded-Proto to the specified value, this may be useful if your reverse proxy handle https but is not configured to add X-Forwarded-Proto (example: --xforwardedproto https)
--cheatmode Add some helper UI to facilitate dev-time testing (Default false)
--explorerpostgres Connection string to the postgres database of NBXplorer. (optional, used for dashboard and reporting features)
--btcexplorerurl URL of the NBXplorer for BTC (default: http://127.0.0.1:24444/)
--btcexplorercookiefile Path to the cookie file (default: /var/lib/btcpay/.nbxplorer/Main/.cookie)
--btclightning Easy configuration of lightning for the server administrator: Must be a UNIX socket of c-lightning (lightning-rpc) or URL to a charge server (default: empty)
--btcexternallndgrpc The LND gRPC configuration BTCPay will expose to easily connect to the internal lnd wallet from an external wallet (default: empty)
--btcexternallndrest The LND REST configuration BTCPay will expose to easily connect to the internal lnd wallet from an external wallet (default: empty)
--btcexternalrtl The Ride the Lightning configuration so BTCPay will expose to easily open it in server settings (default: empty)
--btcexternalspark Show spark information in Server settings / Server. The connection string to spark server (default: empty)
--btcexternalcharge Show lightning charge information in Server settings/Server. The connection string to charge server (default: empty)
-c | --conf The configuration file
-p | --port The port on which to listen
-b | --bind The address on which to bind
-d | --datadir The data directory
⚠️ 注意:
--help打印完参数表后,进程会继续走配置加载,因未提供数据库等启动参数而报fail: Configuration: Configuration error退出——这是正常现象,不代表安装有问题。
4.2 NBXplorer 通用参数
NBXplorer 2.6.19 的 dotnet NBXplorer.dll --help 输出分两部分:每个受支持链一组 <链名>.* 参数(完整链清单见 6.2),以及尾部一组通用参数。通用参数实测如下:
--customkeypathtemplate Define an additional derivation path tracked by NBXplorer (Format: m/1/392/*/29, default: empty)
--maxgapsize The maximum gap address count on which the explorer will track derivation schemes (default: 30)
--mingapsize The minimum gap address count on which the explorer will track derivation schemes (default: 20)
--trimevents When NBXplorer starts, NBXplorer will remove old events to reach this count. No trimming if equals to less than 0 (default: -1)
--signalfilesdir The directory where files signaling if a chain is ready is created (default: the network specific datadir)
--noauth Disable cookie authentication
--instancename Define an instance name for this server that, if not null, will show in status response and in HTTP response headers (default: empty)
--exposerpc Expose the node RPC through the REST API (default: false)
--postgres Use PostgreSQL backend. Set the connection string of the postgres backend (For example: "User ID=postgres;Host=postgres;Port=5432;Application Name=nbxplorer;Database=nbxplorer", more options on https://www.npgsql.org/doc/connection-string-parameters.html)
--socksendpoint Configure a SocksV5 endpoint as proxy to connect to P2P
--socksuser SocksV5 username credential
--sockspassword SocksV5 password credential
-v | --verbose Verbose logs (default: false)
-c | --conf The configuration file
-p | --port The port on which to listen
-b | --bind The address on which to bind
-d | --datadir The data directory
网络参数(与主程序同名同义):-n | --network、--testnet、--regtest、--signet、--chains。
五、BTCPay Server 核心参数分类详解
5.1 网络与链参数
-n | --network:选择 Bitcoin 网络,取值 mainnet/testnet/regtest(--help 显示 signet 也可用 --signet 开关指定)。默认 mainnet。它决定数据目录子目录名、默认端口与所连接链的类型。--testnet/--regtest/--signet 是旧开关,帮助文本已标注 deprecated,新配置统一用 --network。
--chains(短参 -c,注意与 --conf 同为 -c,全参无歧义):要支持的链,逗号分隔。官方 2.4.5 镜像编译进链清单为 btc 一种,故帮助文本写 (default: btc; available: btc)。原生安装若未装多链插件,同样只有 BTC。
--nodefaultchain:布尔开关。设置了它且未显式给 --chains 时,主程序允许零链启动(常用于纯管理节点或分层验证配置连通性)。官方 Docker 部署的实测组合是 BTCPAY_NODEFAULTCHAIN=true + BTCPAY_CHAINS=btc:先生成零链配置再显式挂 BTC。
--deprecated:允许使用已废弃的配置项(默认 false)。升级旧实例时若日志提示某配置已废弃,需要临时加此参数过渡。
启动日志中这组参数的实测确认行:
info: Configuration: Supported chains: BTC
info: Configuration: Network: Regtest
5.2 数据库参数
--postgres:主程序业务库(发票、用户、商店、策略)的 PostgreSQL 连接串,Npgsql 格式。这是唯一必填的启动参数(缺了它启动直接报 Configuration error)。实测两种形态的值:
# Docker Compose 形态(容器内主机名 postgres,库名带网络后缀)
BTCPAY_POSTGRES=User ID=postgres;Host=postgres;Port=5432;Application Name=btcpayserver;Database=btcpayserverregtest
# 原生 systemd 形态(本机 PostgreSQL,独立业务库)
--postgres="User ID=btcpay;Password=q1w2e3r4;Host=127.0.0.1;Database=btcpayservermainnet"
连接串常用键:User ID、Password、Host、Port、Database、Application Name(在 PG 会话列表里区分应用)、MaxPoolSize(连接池上限,Docker 部署对 NBXplorer 库的连接串显式给了 MaxPoolSize=80)。更多参数见 Npgsql 官方 connection-string 文档。
--explorerpostgres:NBXplorer 库的只读连接串(可选)。配置后主程序仪表盘与报表功能直接读 NBXplorer 库,启动日志会出现确认行:
info: Configuration: Connection to NBXplorer's database successful, dashboard and reporting features activated.
不配置时仪表盘报表区不激活,其余功能不受影响。注意权限上应使用只读账号。
💡 技术拓展:主程序与 NBXplorer 必须分库(如
btcpayservermainnet与nbxplorermainnet),不能共库——NBXplorer 的链上索引表体量大、写入频繁,与业务库混跑会互相拖累且备份粒度变差。官方 Compose 生成的配置(实测)即两个独立Database=。
5.3 NBXplorer 连接参数
--btcexplorerurl:BTC 链对应的 NBXplorer API 地址。默认值随网络:主网 http://127.0.0.1:24444/(--help 实测),regtest 实测为 http://127.0.0.1:24446/(原生)或 http://nbxplorer:32838/(Docker 栈内服务名 + 生成端口)。Docker 形态该地址由生成器写死进环境变量 BTCPAY_BTCEXPLORERURL。
--btcexplorercookiefile:访问 NBXplorer API 的 cookie 凭据文件路径。默认 /var/lib/btcpay/.nbxplorer/Main/.cookie(主网默认),NBXplorer 数据目录换了非默认位置时必须显式指向(B1 部署实测值为 /var/lib/nbxplorer/RegTest/.cookie)。cookie 文件内容为单行 HTTP Basic 凭据,格式 __cookie__:<十六进制密钥>,实测样例(节选):
__cookie__:e5b34334099fa5c2c663035b696be672891690f91411dc1bc…
认证是否可用可立即验证(401 表示没带凭据或凭据错误,200 表示通过):
curl -s -o /dev/null -w "%{http_code}\n" http://127.0.0.1:24446/v1/cryptos/btc/status
# 实测输出:401
curl -s -u "$(cat /var/lib/nbxplorer/RegTest/.cookie)" http://127.0.0.1:24446/v1/cryptos/btc/status | head -c 120
# 实测输出(节选):
{"bitcoinStatus":{"blocks":103,"headers":103,…
对应主程序启动日志确认行:
info: Configuration: BTC: Explorer url is http://127.0.0.1:24446/
info: Configuration: BTC: Cookie file is /var/lib/nbxplorer/RegTest/.cookie
多链部署时按 <链小写>explorerurl / <链小写>explorercookiefile 规则派生(如 --ltcexplorerurl),单 BTC 部署用不到。
5.4 Web 服务参数
-p | --port:HTTP 监听端口。默认值随网络:mainnet 23000、testnet 23001、regtest 23002(regtest 值来自 3.3 自动生成模板实测,其余为源码默认值口径)。官方 Docker 栈实测绑定 0.0.0.0:49392(生成器分配的容器内端口,避免与宿主机已有节点冲突)。
-b | --bind:监听地址,默认 127.0.0.1。要给反向代理转发必须改为 0.0.0.0(原生形态)或保持生成器写入的 0.0.0.0:49392(Compose 形态)。
--rootpath:URL 根路径,默认 /。反代场景需要挂在子路径时设为如 /btcpay(对应环境变量 BTCPAY_ROOTPATH)。
--xforwardedproto:反代终止了 HTTPS 但没加 X-Forwarded-Proto 头时,用它强制指定(如 https),否则主程序可能生成 http:// 的回调链接。
--httpscertificatefilepath / --httpscertificatefilepassword:进程自带 TLS 证书(PFX)路径与密码,仅裸跑无反代时使用;生产一律由 Nginx/Caddy 反代终止 TLS,这两项保持默认。
监听生效的实测确认:
info: Configuration: Now listening on: http://0.0.0.0:23000
info: Configuration: Root Path: /
5.5 安全参数
--nocsp:禁用内容安全策略 CSP 头(默认开启 CSP)。仅调试页面资源时临时开启。
--disablessrfprotection:关闭出站请求的 SSRF 防护(默认开启,禁止解析到内网地址的出站请求)。
--ssrfexceptions:SSRF 白名单,逗号或分号分隔的精确主机名、IP、CIDR,可带端口(帮助文本示例:nas.home.arpa:8080;10.8.0.0/24;[fd00::/8]:443)。给受保护的自托管内网服务(如私有汇率源、Electrum 服务)放行时用精确值白名单而不是直接关防护。
--disable-registration:禁用新用户注册,默认 true(已禁用)。注意这与直觉相反:首个注册用户成为管理员后,生产应保持禁用,需要加用户时由管理员在服务器设置里创建或临时放开。
--cheatmode:开发辅助 UI 开关(默认 false),生产禁用。
5.6 日志参数
--debuglog:滚动日志文件路径。Docker 部署实测 BTCPAY_DEBUGLOG=btcpay.log,落到数据目录(实测文件 /datadir/btcpay.log,日志确认行 info: Configuration: LogFile: /datadir/btcpay.log)。
--debugloglevel:日志级别,默认 information。排障时可改 debug(实测栈日志显示 info: Configuration: Log Level: Debug)。该文件按天滚动,文件名形态为 btcpayYYYYMMDD.log(实测 btcpay20261023.log)。
5.7 Lightning 与外部服务参数
--btclightning:给服务器管理员快捷接入 Lightning:值为 c-lightning 的 UNIX socket(如 /root/.lightning/lightning-rpc)或 charge 服务器 URL。官方模板注释里给了两种取值示例(见 3.3 模板 #BTC.lightning= 两行)。
--btcexternallndgrpc / --btcexternallndrest:把内部 LND 钱包的 gRPC/REST 连接信息暴露给外部钱包 App 扫码连接。
--btcexternalrtl / --btcexternalspark / --btcexternalcharge:在「服务器设置 → 服务」页展示 RTL 面板、Spark 电量信息与 Lightning Charge 的入口连接串。
--externalservices:自定义外链列表,格式 service1:path1;service2:path2,同样出现在服务器设置的服务列表里。
💡 说明:这组参数只做「入口注册与展示」,Lightning 节点本身的部署由 Compose 片段(
BTCPAYGEN_LIGHTNING=clightning/lnd/phoenixd)或独立安装完成;单 BTC 主链未启用 Lightning 时整组留空即可。
5.8 btcpay-host 与 Tor 参数
--btcpayhostenabled / --btcpayhostexecutable:btcpay-host 集成开关与可执行文件路径(默认 btcpay-host)。btcpay-host 让主程序通过受限 SSH 在宿主机执行域名变更、清理等宿主侧操作。官方栈实测 BTCPAY_BTCPAYHOSTENABLED=true,并挂载专用 SSH 私钥 BTCPAY_SSHKEYFILE=/root/.ssh/btcpay_host_id_ed25519。
--torrcfile / --torservices / --socksendpoint:Tor 隐藏服务配置——torrc 文件路径、服务 onion 主机名清单(格式 btcpayserver:host.onion:80;btc-p2p:host2.onion:81)、访问 onion 的 Socks5 代理。仅 Tor 片段部署时由生成器注入。
--updateurl:每日新版本检查的 API 地址,默认取 GitHub Releases 最新版接口(官方栈实测 https://api.github.com/repos/btcpayserver/btcpayserver/releases/latest);留空则关闭检查。
六、NBXplorer 参数详解
6.1 通用参数
| 参数 | 默认值 | 说明 |
|---|---|---|
-d | --datadir | $HOME/.nbxplorer | 数据目录,网络子目录 RegTest/Main 在其下;实测栈内为 /datadir |
-p | --port | mainnet 24444 / regtest 24446 | REST API 监听端口 |
-b | --bind | 127.0.0.1 | 监听地址,反代场景改 0.0.0.0 |
-n | --network | mainnet | Bitcoin 网络 |
--chains | btc | 支持的链,逗号分隔 |
--postgres | 文件存储(不启用) | PostgreSQL 后端连接串;官方栈实测必配,未配置时退回文件索引模式 |
--trimevents | -1(不裁剪) | 启动时把事件表裁剪到该条数;官方栈实测设 10000 |
--signalfilesdir | 网络子目录 | 就绪信号文件目录(实测栈内 /datadir,其中生成 btc_fully_synched 文件) |
--maxgapsize / --mingapsize | 30 / 20 | HD 钱包地址缺口窗口上下限,扫描派生地址的范围 |
--customkeypathtemplate | 空 | 追踪额外派生路径(格式 m/1/392/*/29) |
--noauth | 关 | 关闭 cookie 认证(仅本机调试用,暴露端口时严禁开启) |
--instancename | 空 | 实例别名,出现在状态响应与 HTTP 响应头 |
--exposerpc | false | 把节点 RPC 透传到 REST API |
--dbcache | 50(MB) | 数据库缓存,大索引机器可调大 |
--verbose | false | 详细日志 |
--socksendpoint / --socksuser / --sockspassword | 空 | P2P 出站走 SocksV5 代理(Tor 场景) |
启动日志中生效值的实测确认行:
info: Configuration: NBXplorer version 2.6.19
info: Configuration: Data Directory: /datadir
info: Configuration: Configuration File: /datadir/RegTest/settings.config
info: Configuration: Network: Regtest
info: Configuration: Supported chains: BTC
info: NBXplorer.DatabaseSetup: Postgres services activated
6.2 BTC 链参数
每个受支持链(--chains 帮助文本列出 agm,btc,btx,ltc,doge,pepe,bch,grs,btg,dash,trc,polis,mona,ftc,ufo,via,xmcc,gbx,colx,chc,lbtc,qtum,html,mue)都有一组同构参数,BTC 链实测如下:
| 参数 | 默认值 | 说明 |
|---|---|---|
--btcrpcurl | 按网络默认 RPC 端口 | Bitcoin Core RPC 地址;regtest 默认 http://127.0.0.1:18443/(模板实测) |
--btcrpcuser / --btcrpcpassword | cookie 认证 | RPC 用户名/密码(认证方式一) |
--btcrpccookiefile | 按网络数据目录 cookie | RPC cookie 文件路径(认证方式二,默认) |
--btcrpcauth | 空 | user:password 或 cookiefile=path 原始串(认证方式三) |
--btcnodeendpoint | 本机默认 P2P 端口 | P2P 连接(regtest 18444),NBXplorer 靠它收块 |
--btcrpcdefaultwallet | 空 | RPC wallet 上下文;不配置则热钱包生成功能被禁用(见 FAQ) |
--btcstartheight | 首启同步高度 | 从该高度开始扫描 |
--btcrescan / --btcrescaniftimebefore | 0 / 空 | 强制从 startheight 重扫 / 仅当早于某 Unix 时间戳才重扫 |
--btcminutxovalue | -1(禁用) | 追踪 UTXO 的最小聪数,过滤灰尘 |
--btcexposerpc | false | 透传该链节点 RPC |
连接成功的实测日志:
info: NBXplorer.Indexer.BTC: TCP Connection succeed, handshaking...
info: NBXplorer.Indexer.BTC: Handshaked
info: NBXplorer.Indexer.BTC: Testing RPC connection to http://bitcoind:43782/
💡 技术拓展:NBXplorer 连 Bitcoin Core RPC 支持 3 种认证写法,优先级与选型——
方式 写法 适用 cookie(默认) --btcrpccookiefile=<datadir>/.cookie单机同用户,零密码管理 用户名/密码 --btcrpcuser=xx --btcrpcpassword=xx跨机或跨用户访问 原始串 --btcrpcauth=user:password或cookiefile=path一行写死的场景 本文实测采用「用户名/密码」(原生 B1 部署,
bitcoin.conf显式rpcuser/rpcpassword)与「cookie」(Docker 栈,同卷共享.bitcoincookie)两种。
6.3 参数的三种拼法与映射表
同一参数在三个渠道的拼法不同但等效:命令行用连字符全小写;配置文件键对链级参数用点分;环境变量 = 前缀 + 连字符改下划线全大写。实测佐证——NBXplorer 启动日志在 RPC wallet 未配置时同时给出两种拼法:
info: NBXplorer.Indexer.BTC: BTC: RPC wallet features are disabled because neither `BTC.rpc.defaultwallet` nor `NBXPLORER_BTC_RPC_DEFAULTWALLET` is configured.
官方 Docker 栈实测注入的环境变量与对应参数:
| 容器 | 环境变量(实测值) | 等价参数 |
|---|---|---|
| btcpayserver | BTCPAY_NETWORK=regtest | --network=regtest |
| btcpayserver | BTCPAY_CHAINS=btc | --chains=btc |
| btcpayserver | BTCPAY_POSTGRES=User ID=postgres;…;Database=btcpayserverregtest | --postgres=… |
| btcpayserver | BTCPAY_BTCEXPLORERURL=http://nbxplorer:32838/ | --btcexplorerurl=… |
| btcpayserver | BTCPAY_EXPLORERPOSTGRES=User ID=postgres;…;Database=nbxplorerregtest | --explorerpostgres=… |
| btcpayserver | BTCPAY_BIND=0.0.0.0:49392 | --bind=0.0.0.0 --port=49392 |
| btcpayserver | BTCPAY_ROOTPATH=/ | --rootpath=/ |
| btcpayserver | BTCPAY_DEBUGLOG=btcpay.log | --debuglog=btcpay.log |
| btcpayserver | BTCPAY_UPDATEURL=https://api.github.com/repos/btcpayserver/btcpayserver/releases/latest | --updateurl=… |
| btcpayserver | BTCPAY_DATADIR=/datadir | --datadir=/datadir |
| nbxplorer | NBXPLORER_NETWORK=regtest | --network=regtest |
| nbxplorer | NBXPLORER_CHAINS=btc | --chains=btc |
| nbxplorer | NBXPLORER_BIND=0.0.0.0:32838 | --bind=0.0.0.0 --port=32838 |
| nbxplorer | NBXPLORER_POSTGRES=User ID=postgres;…;Database=nbxplorerregtest | --postgres=… |
| nbxplorer | NBXPLORER_BTCRPCURL=http://bitcoind:43782/ | --btcrpcurl=… |
| nbxplorer | NBXPLORER_BTCNODEENDPOINT=bitcoind:39388 | --btcnodeendpoint=… |
| nbxplorer | NBXPLORER_TRIMEVENTS=10000 | --trimevents=10000 |
| nbxplorer | NBXPLORER_SIGNALFILESDIR=/datadir | --signalfilesdir=/datadir |
⚠️ 注意:再次强调 3.1 实测的优先级——这套环境变量会被
settings.config中未注释的同名键压过。Docker 部署要改参数时,优先改环境变量(走 7.3 流程重生成),不要在容器数据卷的settings.config里解除注释,除非明确想覆盖生成器给的值。
七、Docker Compose 部署的环境变量配置
7.1 生成机制:从 BTCPAYGEN_* 到容器环境变量
官方 btcpayserver-docker 的配置生成是一条「栈级环境变量 → 片段合成 → Compose 文件 → 容器环境变量」的流水线,实测全链路如下:
- 栈级变量快照:
btcpay-setup.sh -i执行时把BTCPAYGEN_*等变量写入两处——/root/.env(env 文件)与/etc/profile.d/btcpay-env.sh(登录 shell 自动加载)。实测内容:
# /root/.env(实测)
BTCPAY_PROTOCOL=http
BTCPAY_HOST=btcpay.local
REVERSEPROXY_HTTP_PORT=80
REVERSEPROXY_HTTPS_PORT=443
NBITCOIN_NETWORK=regtest
BTCPAY_CRYPTOS=btc
# ……(其余键默认留空)
# /etc/profile.d/btcpay-env.sh(实测节选)
export COMPOSE_HTTP_TIMEOUT=180
export BTCPAYGEN_CRYPTO1=btc
export BTCPAYGEN_LIGHTNING=none
export BTCPAYGEN_REVERSEPROXY=none
export BTCPAYGEN_ADDITIONAL_FRAGMENTS=''
export BTCPAY_DOCKER_COMPOSE=/root/btcpayserver-docker/Generated/docker-compose.generated.yml
export BTCPAY_BASE_DIRECTORY=/root
export BTCPAY_ENV_FILE=/root/.env
# 随后脚本会把 /root/.env 的非注释行也逐行 export
- 片段合成:生成器按
BTCPAYGEN_CRYPTO1..9、BTCPAYGEN_LIGHTNING、BTCPAYGEN_REVERSEPROXY、BTCPAYGEN_ADDITIONAL_FRAGMENTS、BTCPAYGEN_EXCLUDE_FRAGMENTS选取 compose 片段,合成到Generated/docker-compose.generated.yml。实测本栈生效片段可用btcpay-fragments show核对:
{"excludedFragments":[],"additionalFragments":[],"effectiveFragments":["bitcoin","btcpay-host","btcpayserver","btcpayserver-noreverseproxy","nbxplorer","opt-mempoolfullrbf","postgres"],"availableFragments":["beldex","bitcoin","bitcoin-clightning","bitcoin-lnd","bitcoincore","btcpay-host","btcpayserver","btcpayserver-nginx",…
- Compose 文件落盘:
Generated/docker-compose.generated.yml中,栈级变量经${VAR:-默认值}插值成每个服务的容器环境变量,实测节选:
services:
btcpayserver:
image: ${BTCPAY_IMAGE:-btcpayserver/btcpayserver:2.4.5}
environment:
BTCPAY_POSTGRES: User ID=postgres;Host=postgres;Port=5432;Application Name=btcpayserver;Database=btcpayserver${NBITCOIN_NETWORK:-regtest}
BTCPAY_NETWORK: ${NBITCOIN_NETWORK:-regtest}
BTCPAY_BIND: 0.0.0.0:49392
BTCPAY_CHAINS: "btc"
BTCPAY_BTCEXPLORERURL: http://nbxplorer:32838/
ports:
- "${NOREVERSEPROXY_HTTP_PORT:-80}:49392"
nbxplorer:
image: nicolasdorier/nbxplorer:2.6.19
environment:
NBXPLORER_NETWORK: ${NBITCOIN_NETWORK:-regtest}
NBXPLORER_BIND: 0.0.0.0:32838
NBXPLORER_TRIMEVENTS: 10000
NBXPLORER_POSTGRES: User ID=postgres;Host=postgres;Port=5432;Application Name=nbxplorer;MaxPoolSize=20;Database=nbxplorer${NBITCOIN_NETWORK:-regtest}
NBXPLORER_BTCRPCURL: http://bitcoind:43782/
NBXPLORER_BTCNODEENDPOINT: bitcoind:39388
- 容器环境变量生效:
docker inspect抽查任一服务的实际注入值应与 6.3 表一致。
这套「环境变量进、Compose 与容器参数出」的机制与 3.1 的优先级叠加后,Docker 形态的改参规则收敛为一句话:栈级变量改 .env/profile 后重跑 setup;容器级参数(BTCPAY_*/NBXPLORER_*)由生成器管理,一般不手工改 Compose 文件(重生成会覆盖),确需覆盖时用自定义片段或直接改配置文件。
7.2 栈级环境变量表
btcpay-setup.sh 支持的栈级变量(帮助文本与官方文档双口径核对,实测生成结果一致):
| 变量 | 默认值 | 作用 |
|---|---|---|
BTCPAY_HOST | 空 | 对外主域名;配 Let's Encrypt 自动 HTTPS 的前提 |
BTCPAY_ADDITIONAL_HOSTS | 空 | 附加域名,逗号分隔 |
BTCPAY_PROTOCOL | https | 对外协议(反代已有 HTTPS 时可设 http) |
BTCPAY_LIGHTNING_HOST | 空 | Lightning 节点公告域名(缺省用 BTCPAY_HOST) |
BTCPAYGEN_CRYPTO1..9 | CRYPTO1=btc | 支持的币种槽位(btc/ltc/grs/ftc/doge/mona/dash/xmr/bdx/lbtc/zec/dcr) |
BTCPAYGEN_LIGHTNING | none | Lightning 实现:clightning/lnd/phoenixd/none |
BTCPAYGEN_REVERSEPROXY | nginx | 反代:nginx(自动 HTTPS)或 none |
BTCPAYGEN_ADDITIONAL_FRAGMENTS | 空 | 追加片段,分号分隔(如 opt-save-storage-xs) |
BTCPAYGEN_EXCLUDE_FRAGMENTS | 空 | 强制排除片段 |
BTCPAYGEN_DOCKER_IMAGE | btcpayserver/docker-compose-generator | 生成器镜像 |
NBITCOIN_NETWORK | mainnet | 全栈网络(mainnet/testnet/regtest/signet) |
BTCPAY_IMAGE | 随片段版本 | 锁定主程序镜像(版本固定手段,如 btcpayserver/btcpayserver:2.4.5) |
REVERSEPROXY_HTTP_PORT / REVERSEPROXY_HTTPS_PORT | 80 / 443 | Nginx 宿主监听端口 |
REVERSEPROXY_DEFAULT_HOST | none | 按 IP 直访时的默认站点 |
NOREVERSEPROXY_HTTP_PORT | 80 | 无反代形态的宿主端口(实测本栈为空,走默认 80 → 容器 49392) |
TRUST_DOWNSTREAM_PROXY | false | 是否信任外部反代转发的 X-Forwarded-* 头 |
LETSENCRYPT_EMAIL / BTCPAY_LETSENCRYPT_HOSTS / ACME_CA_URI | 空 / 自动 / production | ACME 证书申请三件套 |
LIGHTNING_ALIAS | 实现默认 | Lightning 节点别名 |
BTCPAY_UPDATE_CLEAN | true | 更新后清理无引用旧镜像 |
COMPOSE_HTTP_TIMEOUT | 180 | Compose 操作超时秒数(setup 写入 profile 快照) |
7.3 配置变更的标准流程
任何栈级变量变更后,按「导出 → 重跑 setup → 验证」三步走(实测把网络从 regtest 换 mainnet、或加存储裁剪片段都是这条路径):
# 1. 登录 shell 保证快照已加载(bash -l),再导出要改的变量
bash -l
export NBITCOIN_NETWORK="mainnet"
# 2. 重新执行安装(会重新生成 Compose 并滚动重启)
cd /root/btcpayserver-docker && . ./btcpay-setup.sh -i
# 3. 验证生成结果与容器实际注入
grep "NBITCOIN_NETWORK" /root/.env
docker inspect generated_btcpayserver_1 --format '{{range .Config.Env}}{{println .}}{{end}}' | grep BTCPAY_NETWORK
# 实测输出(regtest 栈):
BTCPAY_NETWORK=regtest
⚠️ 注意:重跑 setup 必须在登录 shell(
bash -l或sudo su -)中进行。非登录 shell 里BTCPAYGEN_*未从/etc/profile.d/btcpay-env.sh加载,setup 会报This script must be run as root after running "sudo su -"(实测排障详见《BTCPay Server 2.4.5 Docker Compose 部署指南》第七章)。
八、生产配置模板
以下两套模板对应两种部署形态,口径均为「单 BTC 主链、16GB 内存、NVMe SSD、Nginx 反代、mainnet」。参数已按 4~7 章实测默认值填写,可直接替换后使用。
模板一:原生 systemd 部署(ExecStart 参数)
[Service]
ExecStart=/usr/share/dotnet/dotnet /opt/btcpayserver/BTCPayServer.dll \
--datadir=/var/lib/btcpay \
--network=mainnet \
--postgres="User ID=btcpay;Password=q1w2e3r4;Host=127.0.0.1;Database=btcpayservermainnet" \
--btcexplorerurl=http://127.0.0.1:24444 \
--btcexplorercookiefile=/var/lib/nbxplorer/Main/.cookie \
--port 23000 \
--bind 0.0.0.0
要点:业务库与 NBXplorer 库分库名(btcpayservermainnet / nbxplorermainnet);NBXplorer 用 mainnet 默认端口 24444;cookie 指向 NBXplorer 数据目录实际位置;--bind 0.0.0.0 交给本机 Nginx 反代 443。
模板二:Docker Compose 部署(栈级环境变量)
export BTCPAY_HOST="btcpay.example.com"
export NBITCOIN_NETWORK="mainnet"
export BTCPAYGEN_CRYPTO1="btc"
export BTCPAYGEN_LIGHTNING="clightning"
export BTCPAYGEN_REVERSEPROXY="nginx"
export BTCPAYGEN_ADDITIONAL_FRAGMENTS="opt-save-storage-xs"
export BTCPAY_IMAGE="btcpayserver/btcpayserver:2.4.5"
. ./btcpay-setup.sh -i
要点:BTCPAY_HOST 必须是 DNS 已指向本机的真实域名(Nginx 据此自动签 Let's Encrypt 证书);opt-save-storage-xs 把链数据裁剪到约 25GB( SSD 紧张时再降档,Lightning 节点不建议过激裁剪);BTCPAY_IMAGE 锁版本防升级漂移。其余 BTCPAY_* 容器参数由生成器按 6.3 映射自动写入,无需手填。
九、常见问题
Q1:改了环境变量但不生效?
按 3.1 优先级排查:先看配置文件 <数据目录>/<网络>/settings.config 里对应键是否被解除注释——未注释的文件键优先级高于环境变量(实测:文件 port=23101 压过 BTCPAY_PORT=23103)。把文件键注释回去或删除即可。反过来说,想覆盖生成器的环境变量时也可以利用这一规则。
Q2:docker run 给官方镜像传启动参数全部无效?
实测发现 2.4.5 官方镜像入口为 /app/docker-entrypoint.sh,其内容是:
#!/usr/bin/env bash
echo "$(/sbin/ip route|awk '/default/ { print $3 }') host.docker.internal" >> /etc/hosts
exec dotnet BTCPayServer.dll
exec 行不携带 "$@",docker run 追加的 CMD 参数被整体丢弃,日志固定显示 Configuration File: /datadir/<网络>/settings.config 的默认路径。正确做法是用环境变量传参(-e BTCPAY_PORT=23102),或 --entrypoint dotnet 直接覆盖入口后给参数(实测后者可正常生效)。
Q3:非登录 shell 重跑 btcpay-setup.sh 报 must be run as root?
/etc/profile.d/btcpay-env.sh 只有登录 shell 自动加载;普通 shell 里 BTCPAYGEN_* 为空触发脚本保护。用 bash -l 进入登录 shell 再执行(详见 7.3 与《BTCPay Server 2.4.5 Docker Compose 部署指南》)。
Q4:主程序连 NBXplorer 返回 401?
cookie 文件路径与 NBXplorer 实际数据目录不一致所致。NBXplorer 换过 --datadir 后,cookie 在新目录的 <网络>/.cookie(B1 实测:从默认 ~/.nbxplorer 移到 /var/lib/nbxplorer 后,必须同步改 --btcexplorercookiefile)。用 5.3 的 curl 命令可即时定位是凭据问题还是路径问题。
Q5:NBXplorer 日志提示 RPC wallet features are disabled?
未配置 --btcrpcdefaultwallet(或环境变量/文件键 BTC.rpc.defaultwallet)。该参数指向 Bitcoin Core 里已加载的钱包名;补上并重启后日志变为 BTC: RPC wallet loaded,主程序「生成热钱包」功能恢复。完整排障实录见《Ubuntu 22.04 安装 BTCPay Server 2.4.5 指南》第 5.7 节。
Q6:--help 执行完报 Configuration error 是不是装坏了?
不是。帮助文本打印后进程继续加载配置,因缺数据库参数而退出,属预期行为(NBXplorer 的 --help 同理,末尾会跟一个空引用异常栈)。验证安装是否完好用 systemd 状态或健康接口,不要用 --help。
十、参考链接
- BTCPay Server 官方配置文档(btcpayserver-docker Configuration):https://docs.btcpayserver.org/Docker/
- btcpayserver-docker 仓库 configuration.md:https://github.com/btcpayserver/btcpayserver-docker/blob/master/docs/configuration.md
- btcpayserver-docker 片段目录 fragments.md:https://github.com/btcpayserver/btcpayserver-docker/blob/master/docs/fragments.md
- BTCPay Server 源码配置定义(DefaultConfiguration):https://github.com/btcpayserver/btcpayserver/blob/v2.4.5/BTCPayServer/Configuration/DefaultConfiguration.cs
- NBXplorer 仓库:https://github.com/btcpayserver/nbxplorer
- Npgsql 连接串参数:https://www.npgsql.org/doc/connection-string-parameters.html
- 本专栏配套文档:《BTCPay Server 2.4.5 介绍与选型指南》、《Ubuntu 22.04 安装 BTCPay Server 2.4.5 指南》、《BTCPay Server 2.4.5 Docker Compose 部署指南》