116 字
1 分钟
Nacos 开启鉴权配置
2026-01-23

修改 Nacos 安装目录下的 conf/application.properties 文件。

尚未安装 Nacos?参见 Nacos 配置中心安装指南

开启鉴权#

# 开启鉴权
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true

配置 Token 密钥#

WARNING

2.2.0.1 版本后必须手动配置 Token 密钥,否则无法启动。密钥需为 Base64 编码字符串,原始长度不低于 32 字符。

# 2.1.0 版本后使用此配置项
nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=

生成 Base64 密钥:

echo -n 'YourCustomSecretKey0123456789012' | base64

配置节点身份标识#

nacos.core.auth.server.identity.key=example
nacos.core.auth.server.identity.value=example

完整鉴权配置示例#

### 开启鉴权
nacos.core.auth.system.type=nacos
nacos.core.auth.enabled=true
nacos.core.auth.caching.enabled=true
nacos.core.auth.enable.userAgentAuthWhite=false
### 节点身份标识(集群节点间通信白名单)
nacos.core.auth.server.identity.key=example
nacos.core.auth.server.identity.value=example
### Token 配置
nacos.core.auth.plugin.nacos.token.cache.enable=false
nacos.core.auth.plugin.nacos.token.expire.seconds=18000
nacos.core.auth.plugin.nacos.token.secret.key=VGhpc0lzTXlDdXN0b21TZWNyZXRLZXkwMTIzNDU2Nzg=

配置完成后重启 Nacos 即可生效。

分享

如果这篇文章对你有帮助,欢迎分享给更多人!

Nacos 开启鉴权配置
https://blog.olinl.com/posts/nacos-auth-config/
作者
顾拾柒
发布于
2026-01-23
许可协议
CC BY-NC-SA 4.0

目录