站点路径配置是迅睿CMS稳定运行的基础,直接影响网站性能、安全性和后续维护效率。不合理的路径配置会导致:
本文将通过四个核心步骤,彻底解决这些问题。
登录服务器,执行以下命令查看关键信息:
```bash 查看PHP版本 php -v 查看Web服务器类型 curl -I http://你的域名 查看系统用户和组 id 查看迅睿CMS安装目录权限 ls -la /path/to/xunruicms/ ```
记录输出结果,特别是当前运行PHP的用户(通常是www-data或nginx)。
迅睿CMS的路径配置涉及三个核心文件:
在开始修改前,务必先备份:
```bash cd /path/to/xunruicms/ cp config/config.php config/config.php.bak cp config/database.php config/database.php.bak ```
按照以下结构重新组织目录:
```bash 创建标准化目录结构 mkdir -p /www/xunruicms/ cd /www/xunruicms/ 核心程序目录 mkdir -p app/ 静态资源目录 mkdir -p static/ 上传文件目录 mkdir -p uploads/ 缓存目录 mkdir -p cache/ 日志目录 mkdir -p logs/ 备份目录 mkdir -p backups/ ```
设置正确的目录权限:
```bash 设置所有者(假设Web服务器用户为www-data) chown -R www-data:www-data /www/xunruicms/ 设置目录权限 find /www/xunruicms/ -type d -exec chmod 755 {} \; 设置文件权限 find /www/xunruicms/ -type f -exec chmod 644 {} \; 特殊目录需要写权限 chmod -R 777 /www/xunruicms/uploads/ chmod -R 777 /www/xunruicms/cache/ chmod -R 777 /www/xunruicms/logs/ ```
打开config/config.php,找到并修改以下配置项:
```php // 基础URL配置 $config['base_url'] = 'http://你的域名/'; // 如果使用HTTPS $config['base_url'] = 'https://你的域名/'; // 系统路径配置 $config['system_path'] = '/www/xunruicms/app/'; $config['application_folder'] = 'app'; $config['view_folder'] = ''; // 缓存路径配置 $config['cache_path'] = '/www/xunruicms/cache/'; $config['log_path'] = '/www/xunruicms/logs/'; // 上传路径配置 $config['upload_path'] = '/www/xunruicms/uploads/'; $config['upload_url'] = $config['base_url'] . 'uploads/'; // 静态资源路径 $config['static_path'] = '/www/xunruicms/static/'; $config['static_url'] = $config['base_url'] . 'static/'; // 多站点支持(如果需要) $config['site_domain'] = array( 'default' => '你的主域名', 'mobile' => 'm.你的域名', 'en' => 'en.你的域名', ); ```
```nginx server { listen 80; server_name 你的域名; root /www/xunruicms; index index.php index.html index.htm; 静态资源缓存 location ~ \.(jpg|jpeg|png|gif|ico|css|js|woff|woff2|ttf|svg)$ { expires 365d; add_header Cache-Control "public, immutable"; try_files $uri $uri/ =404; } 上传目录访问控制 location ^~ /uploads/ { internal; expires 30d; } 防止敏感文件被访问 location ~ /\.(ht|git|svn) { deny all; } location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; 重要安全设置 fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; } location / { try_files $uri $uri/ /index.php?$query_string; } } ```
```apache
开启重写引擎
RewriteEngine On
RewriteBase /
设置时区
SetEnv TZ Asia/Shanghai
禁止访问敏感文件
在config/database.php中,确保数据库配置正确:

```php $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => '你的数据库用户名', 'password' => '你的数据库密码', 'database' => 'xunruicms_db', 'dbdriver' => 'mysqli', 'dbprefix' => 'dr_', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '/www/xunruicms/cache/database/', 'char_set' => 'utf8mb4', 'dbcollat' => 'utf8mb4_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); ```
创建数据库缓存目录:
```bash mkdir -p /www/xunruicms/cache/database/ chmod 777 /www/xunruicms/cache/database/ ```
执行以下验证命令:
```bash 1. 检查配置文件语法 php -l /www/xunruicms/config/config.php php -l /www/xunruicms/config/database.php 2. 检查目录权限 ls -la /www/xunruicms/ 3. 检查Web服务器配置 nginx -t Nginx测试配置 apachectl configtest Apache测试配置 4. 重启Web服务 systemctl restart nginx systemctl restart php7.4-fpm 或 systemctl restart apache2 ```
如果遇到权限错误,执行:
```bash 递归修改所有者和权限 chown -R www-data:www-data /www/xunruicms/ find /www/xunruicms/ -type d -exec chmod 755 {} \; find /www/xunruicms/ -type f -exec chmod 644 {} \; chmod -R 777 /www/xunruicms/uploads/ chmod -R 777 /www/xunruicms/cache/ ```
如果页面显示路径错误,检查:
如果需要配置多个站点:
```php // 在config.php中添加 $config['site_domain'] = array( 'default' => 'www.domain1.com', 'site2' => 'www.domain2.com', ); // 为每个站点创建独立的upload和cache目录 mkdir -p /www/xunruicms/uploads/site2/ mkdir -p /www/xunruicms/cache/site2/ ```
创建清理脚本/www/xunruicms/cleanup.sh:
```bash !/bin/bash 清理7天前的缓存文件 find /www/xunruicms/cache/ -type f -mtime +7 -delete 清理30天前的日志文件 find /www/xunruicms/logs/ -type f -mtime +30 -delete 清理临时上传文件(保留30天) find /www/xunruicms/uploads/temp/ -type f -mtime +30 -delete ```
设置定时任务:
```bash 每天凌晨3点执行清理 crontab -e 添加以下行 0 3 /bin/bash /www/xunruicms/cleanup.sh ```
创建监控脚本/www/xunruicms/monitor.sh:
```bash !/bin/bash 检查磁盘空间 df -h /www 检查目录权限 ls -la /www/xunruicms/ | grep -E "(uploads|cache|logs)" 检查最近错误日志 tail -50 /www/xunruicms/logs/log-$(date +%Y-%m-%d).php ```
创建备份脚本/www/xunruicms/backup.sh:
```bash !/bin/bash BACKUP_DIR="/www/xunruicms/backups/$(date +%Y%m%d)" mkdir -p $BACKUP_DIR 备份数据库 mysqldump -u用户名 -p密码 xunruicms_db > $BACKUP_DIR/database.sql 备份配置文件 cp -r /www/xunruicms/config/ $BACKUP_DIR/config/ 备份上传文件(排除缓存) rsync -av --exclude=cache /www/xunruicms/uploads/ $BACKUP_DIR/uploads/ 压缩备份 tar -czf $BACKUP_DIR.tar.gz $BACKUP_DIR rm -rf $BACKUP_DIR ```
易频IT社区是综合性互联网IT技术门户网站,专注分享网络技术、服务器运维、网络安全、编程开发、系统架构、云计算、大数据等行业干货,实时更新IT行业资讯、零基础教程、实战案例,为IT从业者、技术爱好者提供专业的学习交流平台。
Copyright © 2021-2026 易频IT社区. All Rights Reserved. 备案号:闽ICP备2023013482号 网站地图