配置文件
宿主机二进制部署使用 TOML 格式配置;全部参数也可由环境变量提供(优先于配置文件)。
用法
缺省配置源为 /etc/gopanel/config.toml(install.sh 安装时自动生成,sqlite 数据文件为绝对路径);旧安装的 config/config.toml(相对工作目录)兼容回退。 开发态可直接复制示例文件到工作目录:
bash
cp config/config.toml.sample config/config.toml
vim config/config.toml # 按需修改
./GoPanel # 未装 /etc 配置时自动识别工作目录的 config/config.toml自定义路径:
bash
./GoPanel -c=/etc/gopanel/config.toml
# 或
GOPANEL_CONFIG=/etc/gopanel/config.toml ./GoPanel示例
toml
# ---------- 服务 ----------
[server]
port = 12395 # 等价 GOPANEL_PORT / GOPANEL_SERVER_PORT
# ---------- 数据库连接 ----------
[db]
type = "sqlite" # 默认 sqlite;可选 sqlite / mysql / mariadb / postgres
file = "data/gopanel.db" # SQLite 数据文件(相对工作目录),也可用 database 字段
# 以下四项仅 mysql / mariadb / postgres 时生效
user = "root"
password = ""
host = "127.0.0.1" # 可写 host:port
port = 3306
database = "gopanel"
prefix = ""
debug = false # true 时打印每条 SQL
[db.options]
charset = "utf8mb4"
# ---------- 系统 ----------
[sys]
env = "prod" # prod / dev默认使用 SQLite
不写 db.type(或写空字符串)时默认按 SQLite 处理:零外部依赖、单文件落盘, 宿主机复制示例文件后直接 ./GoPanel 就能起服务,数据落在 data/gopanel.db。
toml
[db]
type = "sqlite"
file = "data/gopanel.db" # 相对工作目录;留空即用 data/gopanel.db切换到 MySQL / PostgreSQL 时显式写 type 并补上连接信息即可:
toml
[db]
type = "mysql"
host = "127.0.0.1"
port = 3306
user = "root"
password = ""
database = "gopanel"取值优先级
text
环境变量 > 命令行参数 > config.toml > 内置默认值例如同时存在 GOPANEL_PORT=8080 与 server.port = 9000 时,最终为 8080。
启动自检日志会打印 listen_port 与 listen_port_source,指出最终端口及其来源。
环境变量与配置键的对应
环境变量名 = GOPANEL_ + 配置键大写(. 换成 _):
| 配置键 | 环境变量 |
|---|---|
server.port | GOPANEL_SERVER_PORT(别名 GOPANEL_PORT) |
sys.env | GOPANEL_SYS_ENV(别名 GOPANEL_ENV) |
db.type | GOPANEL_DB_TYPE |
db.host | GOPANEL_DB_HOST |
db.database | GOPANEL_DB_DATABASE(别名 GOPANEL_DB_NAME) |
db.debug | GOPANEL_DB_DEBUG |
完整清单见 环境变量。
关于「站点端口」类配置
本程序是单一监听端口的管理后台,除管理后台端口外不提供任何监听能力。 因此「站点 HTTP/HTTPS 端口、站点根目录、HTTP/2、QUIC、可配置优雅退出时长」 这一类参数不存在(启动参数与配置键均已移除,不再声明)。
需要站点 / HTTPS / HTTP-3 时,由外部 Nginx / Caddy 反代管理后台端口承载。
