了解安企CMS安装后的完整目录结构,掌握主程序、配置文件、模板目录、附件目录、运行时数据等每个关键目录和文件的具体作用,方便后续日常维护和二次开发。
安企CMS 安装后的完整目录结构概览,带你了解每个目录和文件的用途。
一、顶层目录结构
csharp
anqicms/ # 网站根目录
├── anqicms # 主程序可执行文件(Linux/Mac)
├── anqicms.exe # 主程序可执行文件(Windows)
├── config.json # 配置文件(端口、数据库、站点名称等)
├── config.sample.json # 配置示例文件(首次启动自动复制为 config.json)
├── template/ # 🎯 模板目录(重点,见下文详解)
├── public/ # 🎯 Web 根目录(Nginx 运行目录,见下文详解)
├── data/ # 数据目录
│ ├── backup/ # 数据库备份文件
│ ├── cert/ # 支付证书文件
│ └── logs/ # 运行日志
├── cache/ # 缓存目录(文件缓存、模板缓存)
├── locales/ # 国际化语言包
│ ├── zh-CN/ # 简体中文
│ ├── en-US/ # 英文
│ ├── ja-JP/ # 日文
│ ├── ru-RU/ # 俄文
│ ├── pt-BR/ # 葡萄牙文
│ ├── id-ID/ # 印尼文
│ └── bn-BD/ # 孟加拉文
├── dictionary.txt # 中文分词词典(全文搜索用)
├── CHANGELOG.md # 版本更新日志
├── README.md # 项目说明
└── License # AGPL-3.0 开源协议
注意 :仅从编译包(release 模式)解压后看到的是运行必需目录。从 GitHub 克隆源码目录包含更多开发相关文件(
controller/、model/、go.mod等),生产环境部署时可删除。
二、模板目录(template/)详解
template/ 是安企CMS 的模板根目录,每套模板独立一个子目录。系统通过 config.json 识别和加载模板。
2.1 模板配置文件 config.json
每套模板目录下都包含 config.json,默认会自动生成,可手动修改。内容格式如下:
json
{
"name": "默认模板",
"package": "default",
"version": "1.0",
"description": "系统默认模板",
"author": "安企CMS",
"homepage": "",
"created": "2022-05-10 22:29:00",
"template_type": 0,
"status": 0
}
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
name |
string | 否 | 模板显示名称,留空自动取目录名 |
package |
string | 否 | 模板文件夹名,仅支持英文字母和数字 |
version |
string | 否 | 模板版本号 |
description |
string | 否 | 模板介绍说明 |
author |
string | 否 | 模板作者 |
homepage |
string | 否 | 作者网站地址 |
created |
string | 否 | 创建时间,格式 2006-01-02 15:04:05 |
template_type |
int | 否 | 0=自适应,1=代码适配,2=电脑+手机 |
status |
int | 否 | 0=未启用,1=启用中(只能有一套为 1) |
2.2 模板文件组织模式
安企CMS 默认支持文件夹模式组织方式。
文件夹模式
csharp
template/mytemplate/
├── config.json # 模板配置文件(必须)
├── base.html # 公共基础模板(页头/页脚等公共布局)
├── partial/ # 代码片段目录
│ ├── header.html # 页头(导航、Logo)
│ ├── footer.html # 页脚(版权、备案号)
│ ├── sidebar.html # 侧边栏
│ └── pagination.html # 分页组件
│
├── index/
│ └── index.html # 首页
│
├── archive/ # 文章模型(默认模型 table=archive)
│ ├── index.html # 文章模型首页
│ ├── list.html # 文章列表页
│ ├── list-{分类ID}.html # 特定分类的列表页(如 list-5.html)
│ ├── detail.html # 文章详情页
│ └── detail-{文档ID}.html # 特定文档的详情页(如 detail-1.html)
│
├── product/ # 产品模型(table=product)
│ ├── index.html # 产品模型首页
│ ├── list.html # 产品列表页
│ ├── list-{分类ID}.html # 特定产品分类列表页
│ ├── detail.html # 产品详情页
│ └── detail-{文档ID}.html # 特定产品详情页
│
├── page/ # 单页面
│ ├── detail.html # 单页面详情页
│ └── {Url别名}.html # 特定单页面(如 detail-about.html)
│
├── tag/
│ ├── index.html # 标签首页
│ └── list.html # 标签文档列表页
│
├── comment/
│ └── list.html # 评论列表页
│
├── guestbook/
│ └── index.html # 在线留言页
│
├── search/
│ └── index.html # 搜索页
│
├── errors/
│ ├── 404.html # 404 错误页
│ ├── 500.html # 500 错误页
│ └── close.html # 站点关闭提示页
│
└── mobile/ # 手机端模板目录(template_type=2 时使用)
├── index/
│ └── index.html
├── archive/
│ ├── list.html
│ └── detail.html
└── ... # 结构同 PC 端
2.3 模板文件与页面匹配规则
| 页面类型 | 文件夹模式路径 | |----------|---------------|---------------| | 首页 | index/index.html | | 模型首页 | {模型table}/index.html | | 文档列表 | {模型table}/list.html | | 文档详情 | {模型table}/detail.html | | 分类列表(独立模板) | {模型table}/list-{分类ID}.html | | 文档详情(独立模板) | {模型table}/detail-{文档ID}.html | | 单页面 | page/detail.html | | 单页面(独立模板) | page/{Url别名}.html | | 标签首页 | tag/index.html | | 标签列表 | tag/list.html | | 评论列表 | comment/list.html | | 留言页面 | guestbook/index.html | | 搜索页 | search/index.html | | 404 错误 | errors/404.html | | 500 错误 | errors/500.html | | 站点关闭 | errors/close.html |
{模型table}是内容模型中定义的table_name,默认文章模型为archive,产品模型为product。
2.4 模板命名规范
| 规则 | 说明 |
|---|---|
| 文件编码 | 必须使用 UTF-8(无 BOM),否则页面乱码 |
| 文件后缀 | 所有模板文件使用 .html 后缀 |
| 变量命名 | 使用驼峰命名 (首字母大写),如 {{archive.Title}} |
| 自定义模板 | detail-{ID}.html 和 list-{ID}.html 可为特定文档/分类设置独立模板 |
三、Web 根目录(public/)详解
public/ 是 Nginx 反向代理时必须指向的 Web 根目录,包含了所有可直接访问的静态资源。
csharp
anqicms/public/
├── static/ # 静态资源目录
│ ├── default/ # 模板对应文件夹
│ │ ├── css/ # 模板样式文件
│ │ │ ├── style.css
│ │ │ └── ...
│ │ ├── js/ # JavaScript 文件
│ │ │ ├── main.js
│ │ │ └── ...
│ │ └── images/ # 图片资源
│ │ ├── logo.png
│ │ └── ...
├── uploads/ # 上传资源目录(用户上传的图片/文件)
│ ├── images/ # 按年/月自动归档
│ │ ├── 2026/
│ │ │ ├── 01/
│ │ │ ├── 02/
│ │ │ └── ...
│ │ └── ...
├── robots.txt # 爬虫规则(后台可配置)
├── sitemap.xml # Sitemap 索引文件(自动生成)
└── LLMs.txt # AI 索引文件(后台可配置)
四、各目录/文件在生产环境的必要性
| 目录/文件 | 生产必需? | 说明 |
|---|---|---|
anqicms(可执行文件) |
✅ 必需 | 程序本身,没有它无法运行 |
config.json |
✅ 必需 | 配置文件,没有它程序不知道端口和数据库 |
template/ |
✅ 必需 | 模板文件,没有模板前台无法显示 |
public/ |
✅ 必需 | Web 根目录,Nginx 的指向目标 |
data/ |
✅ 必需 | 运行数据(备份、缓存、日志) |
cache/ |
✅ 必需 | 缓存目录 |
locales/ |
✅ 必需 | 多语言包 |
dictionary.txt |
✅ 必需 | 中文分词词典 |
CHANGELOG.md、README.md、License |
❌ 可删除 | 纯文档文件 |
五、安全提醒:public/ 的根目录配置
务必确保 Nginx 配置中的 root 指向 public/ 目录,而不是 anqicms/ 根目录:
nginx
# ❌ 错误 ------ 用户可直接访问 config.json、template/ 等敏感文件
root /data/wwwroot/anqicms;
# ✅ 正确 ------ 外部只能访问 public/ 下的资源
root /data/wwwroot/anqicms/public;