适用场景:无面板的 Linux 服务器(如 CentOS / Ubuntu),适合熟悉命令行操作的用户。通过下载安装包、配置 Nginx 反向代理和 MySQL 数据库的方式完成部署。
前置准备
- 一台 Linux 服务器(CentOS 7+ 或 Ubuntu 20.04+)
- 已安装 Nginx 和 MySQL 5.6.35+(推荐使用 LNMP 一键安装包)
- 一个已解析到服务器的域名
- 已下载 AnQiCMS Linux 安装包
安装步骤
Step 1:下载并解压
bash
# 登录服务器
ssh root@your-server-ip
# 下载安装包(以 v3.6.2 为例)
wget https://github.com/fesiong/anqicms/releases/download/v3.6.2/anqicms-linux-v3.6.2.zip
# 创建站点目录
mkdir -p /data/wwwroot/anqicms
# 解压安装包
unzip anqicms-linux-v3.6.2.zip -d /data/wwwroot/anqicms
# 进入站点目录
cd /data/wwwroot/anqicms
# 查看文件列表
ls -la
解压后的目录结构:
bash
/data/wwwroot/anqicms/
├── anqicms # 主程序(可执行文件)
├── start.sh # 启动脚本
├── stop.sh # 停止脚本
├── config.json # 配置文件
├── public/ # Web 根目录
├── template/ # 模板目录
└── system/ # 后台管理界面
Step 2:启动 AnQiCMS
bash
# 启动前确保 config.json 中的端口配置正确(默认 8001)
cat config.json
# {"server":{"site_name":"","env":"production","port":8001,"log_level":"release"}}
# 执行启动脚本
./start.sh
# 检查是否启动成功
ps -ef | grep anqicms
# 如果看到 anqicms 进程,说明启动成功
Step 3:配置 Nginx 反向代理
创建或编辑 Nginx 站点配置文件:
bash
vim /etc/nginx/conf.d/anqicms.conf
写入以下配置:
nginx
server
{
listen 80;
server_name www.anqicms.com m.anqicms.com;
root /data/wwwroot/anqicms/public;
location @AnqiCMS {
proxy_pass http://127.0.0.1:8001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location / {
try_files $uri $uri/index.html @AnqiCMS;
}
# 静态资源直接由 Nginx 处理,不经过反向代理
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css|ico)$ {
expires 30d;
access_log off;
}
access_log /var/log/nginx/anqicms-access.log;
error_log /var/log/nginx/anqicms-error.log;
}
注意 :将
server_name和root路径替换为你的实际域名和站点路径。
验证配置并重载 Nginx:
bash
# 测试配置是否正确
nginx -t
# 重载 Nginx 使配置生效
nginx -s reload
Step 4:添加计划任务保活
为了让 AnQiCMS 在服务器重启后自动运行,添加 crontab 计划任务:
bash
# 编辑 crontab
crontab -e
# 添加以下行(每分钟检查一次 anqicms 进程)
*/1 * * * * /data/wwwroot/anqicms/start.sh
# 保存并退出(vim 中 :wq)
手动执行一次启动脚本:
bash
./start.sh
Step 5:配置 HTTPS(可选)
推荐使用 Let's Encrypt 免费 SSL 证书:
bash
# 安装 certbot
# CentOS:
yum install certbot python3-certbot-nginx
# Ubuntu:
apt install certbot python3-certbot-nginx
# 获取并自动配置 SSL 证书
certbot --nginx -d www.anqicms.com -d m.anqicms.com
# 按照提示完成验证,certbot 会自动修改 Nginx 配置
Step 6:初始化安装
- 在浏览器中访问
http://www.anqicms.com - 进入初始化安装界面
- 填写数据库信息和管理员账号
Apache 反向代理配置(可选)
如果使用 Apache 而非 Nginx,配置如下:
apache
<VirtualHost *:80>
ServerName www.anqicms.com
ServerAlias m.anqicms.com
DocumentRoot /data/wwwroot/anqicms/public
ProxyPass / http://127.0.0.1:8001/
ProxyPassReverse / http://127.0.0.1:8001/
<Directory /data/wwwroot/anqicms/public>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog /var/log/apache2/anqicms-error.log
CustomLog /var/log/apache2/anqicms-access.log combined
</VirtualHost>
需要启用 Apache 的 proxy 模块:
bash
a2enmod proxy proxy_http
systemctl restart apache2
常用管理命令
bash
# 启动
cd /data/wwwroot/anqicms && ./start.sh
# 停止
cd /data/wwwroot/anqicms && ./stop.sh
# 查看运行状态
ps -ef | grep anqicms
# 查看运行日志
tail -f /data/wwwroot/anqicms/running.log
# 查看启动检测日志
tail -f /data/wwwroot/anqicms/check.log
# 修改端口(编辑 config.json 后重启)
vim /data/wwwroot/anqicms/config.json
# 修改 "port": 8001 为其他端口
验证安装
bash
# 1. 检查进程是否运行
ps -ef | grep anqicms | grep -v grep
# 2. 检查端口是否监听
netstat -tlnp | grep 8001
# 3. 浏览器访问域名,应看到网站首页或安装界面
# 4. 访问 域名/system/ 进入后台
❓ 我安装了 MySQL,但不知道 root 密码是什么,怎么办?
如果是通过 LNMP 一键安装包安装的 MySQL,root 密码通常保存在以下位置:
bash
# LNMP 安装包
cat /root/.mysql_root_password
# 或
cat /usr/local/mysql/root.txt
# 宝塔面板安装的 MySQL
cat /www/server/mysql/default.pass
如果以上都找不到,可以绕过 MySQL 认证来重置密码(以 Ubuntu 为例):
bash
# 1. 停止 MySQL
systemctl stop mysql
# 2. 以跳过权限检查的方式启动
mysqld_safe --skip-grant-tables &
# 3. 无密码登录 MySQL
mysql -u root
# 4. 在 MySQL 命令行中重置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密码';
FLUSH PRIVILEGES;
EXIT;
# 5. 重启 MySQL
systemctl restart mysql
❓ 配置完 Nginx 后,访问域名显示的是 Nginx 默认欢迎页,而不是安装界面,为什么?
这是新手最常犯的错误。原因通常有以下两个:
原因一:Nginx 的 root 路径指向了默认网站目录
bash
# 检查默认网站配置文件中是否还有 server 块
ls /etc/nginx/conf.d/default.conf
# 如果有,暂时将其重命名禁用
mv /etc/nginx/conf.d/default.conf /etc/nginx/conf.d/default.conf.bak
nginx -s reload
原因二:Nginx 配置中的 root 没有指向 public 子目录
nginx
# ❌ 错误
root /data/wwwroot/anqicms;
# ✅ 正确
root /data/wwwroot/anqicms/public;
原因三:DNS 未生效
刚添加的域名解析可能需要几分钟到几小时才能全球生效。可以用以下命令测试:
bash
# 直接通过服务器 IP 测试(如果 AnQiCMS 监听在 8001 端口)
curl -I http://127.0.0.1:8001
# 如果返回 200 或 302,说明 AnQiCMS 正常运行,是 Nginx 或 DNS 的问题
❓ 我修改了 config.json 中的端口为 8080,还需要同步修改哪里?
修改端口后,必须同步修改以下两处:
| 位置 | 修改内容 |
|---|---|
Nginx 配置中的 proxy_pass |
proxy_pass http://127.0.0.1:8080;(而不是 8001) |
| 重启 AnQiCMS | 改完 config.json 后必须重启进程才生效 |
如果不修改 Nginx 的 proxy_pass,Nginx 仍然会尝试把请求转发到 8001 端口,而 AnQiCMS 已经在 8080 端口监听,用户就会看到 502 Bad Gateway。