跳到主要内容

配置项参考

当前代码中的配置主要分布在:

  • src\Services\Host\FreeKit.Host\appsettings*.json
  • src\Services\Host\FreeKit.Job.Host\appsettings*.json
  • src\Services\Host\FreeKit.MessageHandler.Host\appsettings*.json
  • build\compose\freekit_pro_modules\.env(.local)

本文只保留和当前宿主直接相关、且在代码中实际被消费的关键配置段。

宿主路径前缀

宿主配置键默认值
FreeKit.HostASPNETCORE_PATHBASE/kit_api
FreeKit.Job.HostASPNETCORE_PATHBASE/job_api
FreeKit.MessageHandler.HostASPNETCORE_PATHBASE/message_api

这些值直接影响 Swagger、RapiDoc、Hub 和 API 的最终访问地址。

主业务连接(ConnectionStrings)

默认主宿主、Job、Message 都使用 ConnectionStrings 作为主业务库与 Redis 入口。典型结构如下:

"ConnectionStrings": {
"DefaultDB": "0",
"UseJsonMap": true,
"DataType": {
"MySql": 0,
"SqlServer": 1,
"PostgreSQL": 2,
"Oracle": 3,
"Sqlite": 4
},
"MySql": "Data Source=localhost;Port=3306;User ID=root;Password=<password>;Initial Catalog=freekit;Charset=utf8mb4;SslMode=none;",
"SqlServer": "Data Source=.;Initial Catalog=freekit;User ID=sa;Password=<password>;",
"PostgreSQL": "Host=localhost;Port=5432;Username=postgres;Password=<password>;Database=freekit;",
"Sqlite": "Data Source=DB/freekit.db",
"Redis": "localhost:6379,password=<password>,defaultDatabase=1"
}
字段说明
DefaultDB默认数据库类型,实际代码中常用 0(MySQL)
UseJsonMap启用 FreeSql JSON 映射
DataType数据库枚举映射,仅用于表达可选数据源
MySql / SqlServer / PostgreSQL / Sqlite主业务库连接字符串
RedisRedis 连接字符串

扩展连接字符串

配置段典型宿主用途
ShortUrlConnectionStringsHost / Job / MessageFreeKit.Short 模块数据源
LogConnectionStringsHost / Job / MessageSerilog MariaDB Sink
JobConnectionStringsJob任务宿主专用库
MessageConnectionStringsMessage消息宿主专用库
SampleAppConnectionStringsHost / Job / Message平台工具/样例应用相关配置

MeiliSearch

"MeiliSearch": {
"Enable": false,
"Host": "http://localhost:17700",
"ApiKey": "<meili-master-key>"
}
字段说明
Enable是否启用搜索引擎
HostMeiliSearch 服务地址
ApiKey访问密钥

CmsKitSearchController、后台初始化接口以及 Job 宿主中都会消费这一配置。

搜索与缓存

"Search": {
"ArticleSuggestionScore": 1.0,
"ShortMsgSuggestionScore": 0.5
}
字段说明
ArticleSuggestionScore文章搜索结果权重分(用于搜索建议排序)
ShortMsgSuggestionScore沸点搜索结果权重分

Cache

"Cache": {
"Enable": true,
"ExpireSeconds": 600
}
字段说明
Enable是否启用缓存
ExpireSeconds某些宿主下的默认缓存过期时间

文件存储

当前代码里同时存在两个相关配置段:

FileStorageOption

供部分模块读取的基础配置:

"FileStorageOption": {
"RootPath": "E:\\files",
"FileTableCount": 64
}
字段说明
RootPath本地文件根目录
FileTableCount分表数量

FileStorage

更完整的文件上传与存储实现配置:

"FileStorage": {
"MaxFileSize": 83886080,
"NumLimit": 3,
"Exclude": ".exe,.dll,.jar",
"ServiceName": "LocalFileManager",
"LocalFile": {
"PrefixPath": "assets",
"Host": "https://localhost:7002/"
}
}

IdentityCmsKit 等模块会直接消费这一段。

短链配置(ShortUrlOption)

"ShortUrlOption": {
"Salt": "ShortUrlApi",
"MinHashLength": 6,
"FileTableCount": 64
}
字段说明
SaltHashids 加盐值,生产环境应换为随机字符串
MinHashLength短链最小字符长度
FileTableCount短链分表数量

Swagger 保护(Basic)

"Basic": {
"Enable": false,
"ProtectPaths": [
"/swagger/v1/swagger.json",
"/swagger/index.html"
],
"Realm": "https://yourdomain.com/",
"UserName": "<user>",
"UserPassword": "<password>"
}

用于保护 Swagger 相关资源。

认证与安全

Authentication

"Authentication": [
{
"Schemes": {
"ValidIssuer": "Issuer",
"ValidAudience": "Audience",
"SigningKeys": [
{
"Value": "<64-char-key>"
}
]
}
}
]

Security

"Security": {
"ValidToken": {
"Enable": true
},
"Cryptography": {
"Key": "<crypto-key>"
},
"Sso": {
"TokenExpiresIn": 86400,
"CodeExpiresInMinutes": 5
},
"AuthOptions": {
"EmailConfirmationUrl": "https://localhost:7002/.../{uid}/{token}",
"PasswordResetUrl": "https://localhost:7002/.../{uid}/{token}"
}
}

IdentityModuleStartup 会绑定其中的 AuthOptionsSso 相关配置。

OAuthRedirectWhitelistDomains

"OAuthRedirectWhitelistDomains": [
"localhost",
"yourdomain.com"
]

用于第三方登录回调域名白名单。

CAP

"CAP": {
"Version": "Development",
"DefaultStorage": "1",
"DefaultMessageQueue": "1",
"RabbitMQ": {
"HostName": "localhost",
"UserName": "<user>",
"Password": "<password>",
"Port": 5672,
"VirtualHost": "/admin"
}
}

Host、Job、Message 三个宿主都会消费 CAP 配置,但具体使用方式略有不同。

内部服务地址(Host)

"Host": {
"IdentityApi": "https://localhost:7002"
}

例如 CmsKitModuleStartup 会用它注册命名 HttpClient("IdentityApi")

其他常见配置段

配置段用途
Captcha验证码开关与过期时间
RecaptchaSettingsGoogle reCAPTCHA
MailKitOptions邮件发送
Serilog日志输出
DailyHot热榜采集 Cookie 等配置
AppOption / CnBlogAppOption / M3U8AppOption平台工具类配置

Docker 环境变量

Compose 通过环境变量覆盖应用配置,关键值在 build\compose\freekit_pro_modules\.env

TZ=Asia/Shanghai
MYSQL_PORT=13306
REDIS_PORT=16379
RABBITMQ_PORT=5672
RABBITMQ_MANAGEMENT_PORT=15673
MEILI_PORT=17700
HOST_API_PORT=18080
JOB_API_PORT=18081
MESSAGE_API_PORT=18082

MYSQL_ROOT_PASSWORD=<change-me>
REDIS_PASSWORD=<change-me>
RABBITMQ_USER=rabbitmq
RABBITMQ_PASSWORD=<change-me>
RABBITMQ_VHOST=freekit_api_prod
MEILI_MASTER_KEY=<change-me>

MYSQL_CONN_FREEKIT=<connection-string>
MYSQL_CONN_JOB=<connection-string>
MYSQL_CONN_SHORTURL=<connection-string>
MYSQL_CONN_LOG=<connection-string>
REDIS_CONN=<connection-string>

建议把真实值写入 .env.local,不要直接修改或提交模板文件。