FastAdmin 配置文件路径:
application/config.php
'cache' => [
'type' => 'redis','host' => '1Panel-redis-AIf3', // ← 使用容器名称
'port' => 6379,
'password' => 'redis_***',
'select' => 0, //这个值要改不能和其它站一样
'prefix' => 'fastadmin_',//这个值要改不能和其它站一样
'expire' => 0,
],
// +----------------------------------------------------------------------
// | 会话设置
// +----------------------------------------------------------------------
'session' => [
'id' => '',
'var_session_id' => '',
'prefix' => 'sess_', // Session 前缀,避免和缓存混淆 这个值要改不能和其它站一样
'type' => 'redis', // 启用 Redis Session
'auto_start' => true,
// Redis 连接信息(使用容器名称)
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_***',
'select' => 1, // Session 独立使用 DB1 这个值要改不能和其它站一样
],
/////////////////比如3站配置//////////////////////////////////////
📘 三站点 Redis 配置 · 操作步骤文案(FastAdmin / ThinkPHP)
以下步骤适用于:
多站点共用同一个 Redis
每个站点需要独立缓存、独立 Session
避免互相覆盖、互相污染、互相掉线
Docker + 1Panel 环境
Redis 容器名称:
1Panel-redis-AIf3Redis 密码:
redis_***
🟦 步骤 1:为每个站点分配独立 Redis DB
| 站点 | 缓存 DB | Session DB |
|---|---|---|
| Site1 | 0 | 1 |
| Site2 | 2 | 3 |
| Site3 | 4 | 5 |
这样可以确保:
缓存互不干扰
Session 不会互相覆盖
清缓存不会影响其他站点
🟩 步骤 2:为每个站点设置独立 prefix
| 站点 | 缓存前缀 | Session 前缀 |
|---|---|---|
| Site1 | site1_cache_ | site1_sess_ |
| Site2 | site2_cache_ | site2_sess_ |
| Site3 | site3_cache_ | site3_sess_ |
prefix 必须不同,否则会出现:
登录状态混乱
缓存互相覆盖
清缓存导致其他站点掉线
🟧 步骤 3:修改每个站点的 config.php
路径:
Code
application/config.php
🟦 Site1 配置
✔ Cache(DB0)
php
'cache' => [
'type' => 'redis',
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_***',
'select' => 0,
'prefix' => 'site1_cache_',
'expire' => 0,
],
✔ Session(DB1)
php
'session' => [
'id' => '',
'var_session_id' => '',
'prefix' => 'site1_sess_',
'type' => 'redis',
'auto_start' => true,
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_***',
'select' => 1,
],
🟩 Site2 配置
✔ Cache(DB2)
php
'cache' => [
'type' => 'redis',
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_***',
'select' => 2,
'prefix' => 'site2_cache_',
'expire' => 0,
],
✔ Session(DB3)
php
'session' => [
'id' => '',
'var_session_id' => '',
'prefix' => 'site2_sess_',
'type' => 'redis',
'auto_start' => true,
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_***',
'select' => 3,
],
🟧 Site3 配置
✔ Cache(DB4)
php
'cache' => [
'type' => 'redis',
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_****',
'select' => 4,
'prefix' => 'site3_cache_',
'expire' => 0,
],
✔ Session(DB5)
php
'session' => [
'id' => '',
'var_session_id' => '',
'prefix' => 'site3_sess_',
'type' => 'redis',
'auto_start' => true,
'host' => '1Panel-redis-AIf3',
'port' => 6379,
'password' => 'redis_***',
'select' => 5,
],
🟨 步骤 4:清缓存 + 重启 PHP 容器
每个站点修改完后执行:
Code
php think clear
然后在 1Panel 重启对应的 PHP 容器。
🟦 步骤 5:验证 Redis 是否正常写入
进入 Redis:
Code
redis-cli -a redis_E47ppm
查看 Site1 Session:
Code
select 1
keys *
查看 Site2 Session:
Code
select 3
keys *
查看 Site3 Session:
Code
select 5
keys *
如果能看到 key,说明配置成功。


发表评论 取消回复