跳到主内容

配置

Casdoor is configured with one file, conf/app.conf, whose options can also be set as environment variables. This page lists every option.

后端配置(app.conf)​

后端读取一个配置文件:conf/app.conf。对于最小化配置,请为您的数据库设置 driverName 和 dataSourceName(请参阅配置数据库)。下表列出了每个选项。

参数默认值描述
appnamecasdoor应用名称(目前无实际用途)
httpport8000后端应用程序监听的端口
runmodedev运行模式:dev 或 prod
copyrequestbodytrue是否复制请求体以供后续使用
driverNamemysql数据库驱动程序(例如:mysql、postgres、sqlite)。请参阅配置数据库
dataSourceNameroot:123456@tcp(localhost:3306)/数据库连接字符串。请参阅配置数据库
dbNamecasdoorCasdoor 使用的数据库名称
tableNamePrefix(empty)使用适配器时表名的前缀
showSqlfalse当日志级别大于INFO时,在日志中显示 SQL 语句
redisEndpoint(empty)用于会话存储的Redis端点(例如:localhost:6379)。如果为空,会话将存储在本地./tmp中。密码方式:host:port,db,password
sessionCookieLifeTime(empty)会话 Cookie 的有效期(秒)。为空或不大于 0 时默认 30 天(2592000);设置大于 0 的值即可覆盖。
defaultStorageProvider(empty)文件上传(例如头像)的默认存储提供程序名称。请参阅 storage
isCloudIntranetfalse提供者端点是否使用内网地址
authState"casdoor"登录时检查的授权应用名称
socks5Proxy"127.0.0.1:10808"OAuth提供商(Google、GitHub等)的SOCKS5代理地址可能被阻止
verificationCodeTimeout10验证码有效期,单位:分钟
initScore0分配给新用户的初始分数(由Casnode使用,而非Casdoor)
logPostOnlytrue是否只记录 POST 请求
isUsernameLoweredfalse是否将用户名转换为小写
origin(empty)后端源URL(例如:https://door.casdoor.com)
originFrontend(empty)若前后端URL不同则以前端URL为准
trustedProxies(empty)Comma-separated IPs or CIDR ranges of reverse proxies whose X-Forwarded-For and X-Real-IP headers are trusted for the client IP (* trusts any). When empty, loopback and private addresses are trusted
staticBaseUrl"https://cdn.casbin.org"数据库初始化期间使用静态资源的 CDN URL
frontendCdnUrl(empty)Serve the frontend's JavaScript and CSS from a CDN, e.g. https://cdn.jsdelivr.net/npm/{name}@{version}. Only applies to a frontend installed from the casdoor-web npm package; files that fail to load from the CDN are loaded from Casdoor
isDemoModefalse启用演示模式限制
batchSize100批量操作的批量大小
showGithubCornerfalse在界面上显示 GitHub 角操作区
forceLanguage""强制界面使用指定语言(例如 "zh"、"en")。覆盖用户的浏览器语言。空值表示不进行覆盖。
defaultLanguage"en"当未设置浏览器偏好或强制覆盖时的默认UI语言
defaultApplication"app-built-in"登录后未指定具体应用时重定向到的应用程序名称
maxItemsForFlatMenu7平铺(非分组)侧栏菜单中最多显示的项目数。当计数超过此值时,菜单将切换为树状/分组视图
enableErrorMaskfalse是否屏蔽详细错误消息
enableErrorMask2falseReplace every API error message with a generic one, so that responses don't reveal why a request failed
enableGziptrue当客户端支持时,接受并以gzip编码响应
inactiveTimeoutMinutes(empty)自动注销在几分钟后超时。为空或≤0表示无超时
ldapServerPort389LDAP服务器端口
ldapsCertId""LDAPS 连接的证书 ID
ldapsServerPort636LDAPS(LDAP over SSL)服务器端口
radiusServerPort1812RADIUS服务器端口
radiusDefaultOrganization"built-in"RADIUS认证的默认组织
radiusSecret"secret"RADIUS认证共享密钥
gatewayHttpPort80HTTP port of the reverse-proxy gateway for Sites. The gateway only starts when at least one site exists
gatewayHttpsPort443HTTPS port of the reverse-proxy gateway for Sites
acmeEmail(empty)Email of the ACME (Let's Encrypt) account used to issue certificates for Sites
acmePrivateKey(empty)Private key (PEM) of that ACME account
quota{"organization": -1, "user": -1, "application": -1, "provider": -1}资源配额(-1 表示无限制)
logConfig{"adapter":"file", "filename": "logs/casdoor.log", "maxdays":99999, "perm":"0770"}日志配置 (适配器、文件路径、旋转、权限)
initDataNewOnlyfalseOnly add the objects of the init data file that don't exist yet, existing ones are left as they are
initDataMergefalseUpdate the existing objects with only the fields set in the init data file, instead of deleting and re-creating them
initDataFile"./init_data.json"Path to the data initialization file, JSON or YAML (.yaml/.yml). 请参阅数据初始化
initDataWatchInterval0Seconds between the checks of the init data file for changes, a changed file is applied again without a restart. 0 applies it only at startup
frontendBaseDir"../cc_0"前端文件的基础目录 (仅用于开发)

环境变量​

app.conf 中的每个 Casdoor 选项均可通过同名的环境变量进行覆盖。部分 Beego 选项(例如 httpport、appname)也受支持。

示例:通过环境变量传递配置启动Casdoor:

appname=casbin go run main.go

变量也可以在 shell 中使用 export 命令导出。变量名必须与 app.conf 中的键名完全匹配。

备注

环境变量会覆盖 app.conf 中的值。

Frontend configuration​

The web console reads a few settings from the backend at runtime, so you change them in app.conf (or with environment variables) and restart the backend; there is no need to rebuild the frontend:

app.conf optionEffect on the web console
defaultApplicationApplication whose sign-in page is shown when none is specified
showGithubCornerShow the GitHub corner ribbon
isDemoModeRestrict what the console allows, for public demo sites
forceLanguageUse this language for every user, ignoring the browser language
defaultLanguageLanguage used when the browser doesn't ask for a supported one
staticBaseUrlBase URL of static images such as logos and avatars
maxItemsForFlatMenuNumber of top menu items above which the menu is grouped

The compile-time defaults of these settings, plus the default theme (ThemeDefault) and an optional custom footer (CustomFooter), are in web/src/Conf.ts. Changing that file requires rebuilding the frontend with yarn build in the web directory. Per-organization and per-application themes are set in the console instead; see Customize theme.