跳到主内容

配置参考

Casdoor 从一个文件 conf/app.conf 读取设置。你可以使用环境变量覆盖每个选项。本页列出了所有选项。

对于最小化设置,只需设置 driverName、dataSourceName 和 dbName。请参阅 配置数据库。

后端选项​

选项按 conf/app.conf 中的顺序显示。更改选项后需要重启 Casdoor。

OptionDefault描述
appnamecasdoorApplication name. Not used at the moment
httpport8000后端应用程序监听的端口
runmodedev运行模式:dev 或 prod
copyrequestbodytrue是否复制请求体以供后续使用
driverNamemysql数据库驱动程序(例如:mysql、postgres、sqlite)。 See Configure the database
dataSourceNameroot:123456@tcp(localhost:3306)/数据库连接字符串。 See Configure the database
dbNamecasdoorCasdoor 使用的数据库名称
tableNamePrefix(empty)使用适配器时表名的前缀
showSqlfalse当日志级别大于INFO时,在日志中显示 SQL 语句
redisEndpoint(empty)Redis server for the session store and the OAuth device authorization store, in the format host:port[,poolSize[,password[,db]]], for example localhost:6379,100,<redis-password>,2. poolSize defaults to 1000 and db to 0. List several addresses separated by ; in the first field to use Redis Cluster, for example 10.0.0.1:6379;10.0.0.2:6379,100,<redis-password>; db isn't used in cluster mode. If empty, sessions are stored in files in ./tmp and device authorizations in memory. If Redis can't be reached at startup, device authorizations fall back to memory
sessionCookieLifeTime(empty)会话 Cookie 的有效期(秒)。为空或不大于 0 时默认 30 天(2592000);设置大于 0 的值即可覆盖。
defaultStorageProvider(empty)文件上传(例如头像)的默认存储提供程序名称。请参阅 storage
isCloudIntranetfalse提供者端点是否使用内网地址
authState"casdoor"Authorization application name that Casdoor checks during sign-in
socks5Proxy"127.0.0.1:10808"SOCKS5 proxy for OAuth providers (Google, GitHub, etc.) that may be blocked. Use host:port, or socks5://<user>:<password>@host:port for a proxy that requires authentication. If the proxy can't be reached at startup or the URL is invalid, Casdoor connects directly. Email providers with Enable proxy need the plain host:port form, without credentials
verificationCodeTimeout10验证码有效期,单位:分钟
initScore0分配给新用户的初始分数(由Casnode使用,而非Casdoor)
logPostOnlytrueWhether to record only non-GET requests. logout and sso-logout are recorded for GET requests too, for example OpenID Connect RP-initiated logout through GET /api/logout, so that their records and webhooks aren't lost
isUsernameLoweredfalse是否将用户名转换为小写
origin(empty)后端源URL(例如:https://door.casdoor.com)
originFrontend(empty)若前后端URL不同则以前端URL为准
basePath(empty)Path that Casdoor is served under behind a reverse proxy, for example /casdoor. Empty serves Casdoor at the root. See Serve Casdoor under a path
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
formCssAllowedUrls(empty)Comma-separated URL prefixes from which organization admins may load images, fonts, and other files in the custom HTML and CSS of applications, in addition to this Casdoor's origin, the domains of global storage providers, and built-in font and CDN hosts. An entry without a scheme gets https://. See Customize the look of the sign-in page
isDemoModefalseMake the site a read-only public demo: most write requests are refused (sign-in, sign-up, sign-out, verification codes, and users editing their own profile still work), withSecret=1 is refused, and built-in/admin is created with the password 123 when initAdminPassword is empty. A dbName of casdoor_demo applies the same rules except the read-only one, and also refuses changes to the Host, Endpoint, or Type of a provider
batchSize100批量操作的批量大小
showGithubCornerfalse在界面上显示 GitHub 角操作区
forceLanguage""Language of the UI (e.g. "zh", "en") for visitors who haven't picked a language in this browser. Overrides the browser language, but not a language that the user picked. 空值表示不进行覆盖。 See How Casdoor picks the language
defaultLanguage"en"当未设置浏览器偏好或强制覆盖时的默认UI语言
defaultApplication"app-built-in"Name of the application to redirect to after sign-in when no specific application is requested
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)Automatic sign-out timeout in minutes. 为空或≤0表示无超时
ldapServerPort389LDAP服务器端口
ldapsCertId""LDAPS 连接的证书 ID
ldapsServerPort636LDAPS(LDAP over SSL)服务器端口
radiusServerPort1812RADIUS服务器端口
radiusDefaultOrganization"built-in"RADIUS认证的默认组织
radiusSecret"secret"RADIUS 认证和计费的共享密钥。它是所有 RADIUS 客户端共用的一个密钥:Casdoor 不支持每客户端独立密钥
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"}日志配置 (适配器、文件路径、旋转、权限)
initAdminPassword(empty)Password of built-in/admin when Casdoor creates it on an empty database. Existing databases aren't changed. If empty, the first visitor sets the password on the Welcome to Casdoor page, except in demo mode (see isDemoMode). See Sign in to the admin console
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). See Data initialization
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
disableVersionCheckfalse不在系统信息页面上向 GitHub 检查最新的 Casdoor 发布版本,例如在离线或内网部署中。请参阅 升级 Casdoor
disableUpgradefalse隐藏系统信息页面上的发布二进制文件的一键升级按钮,并拒绝升级 API。请参阅 升级 Casdoor
frontendBaseDir"../cc_0"前端文件的基础目录 (仅用于开发)

使用环境变量覆盖选项​

与 app.conf 中某个选项同名的环境变量会覆盖该文件中的值。名称必须与选项名完全匹配,包括大小写。某些 Beego 选项(如 httpport 和 appname)也以相同方式工作。

为单次运行设置变量:

appname=casbin go run main.go

或者在启动 Casdoor 之前将其导出到 shell 中:

export httpport=9000
./casdoor

在 Docker 中,使用 -e 传递选项。请参阅 使用 Docker 尝试。

从文件读取选项​

为了避免将 dataSourceName 或 redisEndpoint 等机密信息放在环境变量中,可以将值放入文件,并将 <option>_FILE 设置为该文件的路径。这适用于 Docker 和 Kubernetes 机密,它们作为文件挂载:

docker run -e driverName=postgres \
-e dataSourceName_FILE=/run/secrets/casdoor_dsn \
casbin/casdoor
  • 此方法适用于本页面上的每个选项。
  • 以选项本身命名的环境变量优先于 <option>_FILE。
  • Casdoor 会忽略文件末尾的换行符,因此使用 echo 写入的文件也能正常工作。
  • 如果无法读取文件,Casdoor 会停止运行并抛出指明选项名称的错误。

影响管理控制台的选项​

前端在运行时从后端读取以下选项。请在 app.conf 中或通过环境变量更改它们并重启后端。你不需要重新构建前端。

OptionEffect on the admin console
defaultApplicationApplication whose sign-in page appears when the request names no application
defaultLanguageLanguage used when the browser doesn't ask for a supported one
forceLanguageLanguage used instead of the browser language, until the user picks another one
isDemoModeMakes the console read-only, for public demo sites. Also shows the Marketplace themes in turn on the sign-in pages and lets visitors switch between them, as does a dbName of casdoor_demo
maxItemsForFlatMenuNumber of top menu items above which the menu is grouped
showGithubCornerShows the GitHub corner ribbon
staticBaseUrlBase URL of static images such as logos and avatars

编译时前端设置​

上述选项的编译时默认值、默认主题 (ThemeDefault) 以及可选的自定义页脚 (CustomFooter) 位于 web/src/Conf.ts。修改该文件后,重新构建前端:

cd web
yarn build

要为单个组织或单个应用设置主题,请使用管理控制台。请参阅 自定义主题。

另请参阅​