SpringBoot+Vue实现流量数据分析与可视化系统
2026/10/14 9:38:40
| 错误码 | 核心原因 | 优先级 |
|---|---|---|
| 403 Forbidden | 目录缺少执行权限(x)、文件权限不足、Nginx 配置拦截 | 最高 |
| 404 Not Found | URL 路径与实际文件路径不匹配、Nginx 路径映射错误 | 高 |
| 500 Internal Server Error | rewrite + alias 路径循环、配置语法错误 | 中 |
bash
运行
# 格式:将URL中 /get_image_by_name/ 后的部分拼接至静态根目录 ls -l /mnt/[静态目录名]/static/[URL中/get_image_by_name/后的完整路径] # 示例:URL = https://域名/get_image_by_name/分组目录/子目录/图片名.png ls -l /mnt/[静态目录名]/static/分组目录/子目录/图片名.pngNo such file or directory→文件路径错误,执行find /mnt/[静态目录名]/static/ -name "图片名.png"查找真实路径;bash
运行
# 1. 修复目标目录执行权限(Nginx必须有x权限才能进入目录) chmod 755 /mnt/[静态目录名]/static/分组目录/子目录/ # 2. 修复目标文件读取权限 chmod 644 /mnt/[静态目录名]/static/分组目录/子目录/图片名.png # 3. 确保归属Nginx运行用户(通常为nginx) chown -R nginx:nginx /mnt/[静态目录名]/static/分组目录/权限标准:
drwxr-xr-x(755);-rw-r--r--(644);nginx:nginx。编辑 Nginx 站点配置文件/etc/nginx/conf.d/[站点配置名].conf,确保图片访问location配置如下(无冲突版):
nginx
location ^~ /get_image_by_name/ { alias /mnt/[静态目录名]/static/; # 关键:直接替换前缀,无rewrite satisfy any; allow all; disable_symlinks off; # 缓存与传输优化 open_file_cache max=1000 inactive=7d; open_file_cache_valid 7d; sendfile on; tcp_nopush on; # 压缩与缓存 gzip on; gzip_types image/jpeg image/png image/webp; expires 7d; add_header Cache-Control "public, max-age=604800"; add_header Access-Control-Allow-Origin *; # MIME类型 types { image/jpeg jpg jpeg; image/png png; image/webp webp; } default_type application/octet-stream; }bash
运行
# 验证配置语法 nginx -t # 常见错误及修复 # 错误1:duplicate directive → 删除重复的配置项(如重复的open_file_cache) # 错误2:invalid parameter → 删除非法参数(如deny none;)bash
运行
systemctl restart nginx curl -I https://域名/get_image_by_name/分组目录/子目录/图片名.pngbash
运行
# 查看最新错误日志 tail -100 /var/log/nginx/[站点错误日志名].log | grep -i "图片名.png" # 常见日志关键词及解决方案 # 关键词1:rewrite or internal redirection cycle → 删除location中的rewrite指令 # 关键词2:permission denied → 重新执行权限修复命令,检查SELinux状态 # 关键词3:no such file or directory → 核对路径映射是否正确bash
运行
# 临时关闭SELinux测试 setenforce 0 curl -I https://域名/get_image_by_name/分组目录/子目录/图片名.png # 若恢复正常,永久关闭SELinux(编辑配置文件) vim /etc/selinux/config # 将 SELINUX=enforcing 改为 SELINUX=disabledbash
运行
# 查看挂载参数 mount | grep /mnt # 若挂载参数含 root_squash → 重新挂载去掉该限制 umount /mnt/[静态目录名] mount -o rw,rootno_squash /dev/[磁盘设备名] /mnt/[静态目录名]创建脚本/root/fix_image_perm.sh,实现目录 / 文件权限自动修复:
bash
运行
#!/bin/bash # 静态文件根目录 STATIC_DIR="/mnt/[静态目录名]/static/分组目录/" # 修复所有子目录权限为755 find $STATIC_DIR -type d -exec chmod 755 {} \; # 修复所有图片文件权限为644 find $STATIC_DIR -type f \( -name "*.jpg" -o -name "*.png" -o -name "*.webp" \) -exec chmod 644 {} \; # 确保归属nginx用户 chown -R nginx:nginx $STATIC_DIR echo "权限修复完成:$(date)" >> /root/fix_image_perm.logbash
运行
chmod +x /root/fix_image_perm.sh crontab -e # 新增一行 0 */1 * * * /root/fix_image_perm.shlocation ^~ /get_image_by_name/中添加rewrite指令,避免与alias冲突;nginx -t验证语法;/mnt/[静态目录名]/static/对应路径下?755,文件权限是否为644?alias /mnt/[静态目录名]/static/,且无rewrite指令?nginx -t无报错)?