当前位置: 首页 > news >正文

Centos 9 Ngnix 文件服务的美化+favicon.ico图标

笔记:
核心:fancyindex

时间: 2025年8月19日13:54:32

更新时间:2025年11月04日 10点26分,更新内容:去掉重新向直接端口访问,添加favicon.ico图标

效果如下:

因为我使用的是Centos 9 需要通过 EPEL 安装fancyindex, Ubuntu/Debian 稍有不同,随便都能搜到。

1、通过 EPEL 安装

sudo dnf install epel-release sudo dnf install nginx-mod-fancyindex

2、创建fancyindex文件夹

mkdir -p /home/chengdong/upload/fancyindex

3、在 fancyindex 文件夹下,创建自定义的网页模板(HTML 页面),没有favicon.ico请删除

<link rel="icon" href="/favicon.ico" type="image/x-icon"> 代码,favicon.ico图标我也是放在fancyindex文件夹

vim /home/chengdong/upload/fancyindex/header.html
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>文件列表 - 澄东的服务器</title> <link rel="icon" href="/favicon.ico" type="image/x-icon"> <style> body { font-family: 'Segoe UI', sans-serif; margin: 2em; } table { width: 100%; border-collapse: collapse; } th { background: #f8f9fa; text-align: left; padding: 12px; } td { padding: 10px; border-bottom: 1px solid #eee; } a { color: #0366d6; text-decoration: none; } .size { color: #6a737d; } .date-col { width: 150px; } </style> <script> document.addEventListener('DOMContentLoaded', function() { // 转换日期格式 const dates = document.querySelectorAll('.date'); const monthNames = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']; dates.forEach(el => { const dateStr = el.textContent.trim(); if(dateStr) { const date = new Date(dateStr); if(!isNaN(date)) { const chineseDate = `${date.getFullYear()}年${monthNames[date.getMonth()]}${date.getDate()}日 ${String(date.getHours()).padStart(2, '0')}:${String(date.getMinutes()).padStart(2, '0')}`; el.textContent = chineseDate; } } }); }); </script> </head> <body> <h1>文件列表</h1>
vim /home/chengdong/upload/fancyindex/footer.html
<footer style="margin-top: 2em; color: #6a737d;"> <hr> <p>© 2025 澄东的文件服务器</p> </footer> </body> </html>
4、权限设置
sudo chown -R nginx:nginx /home/chengdong/upload/fancyindex sudo chmod 755 /home/chengdong/upload/fancyindex

5、修改 nginx 配置文件,如果有 favicon.ico 可以把前面的#注释去掉

# 文件服务器 server { listen 2282; listen [::]:2282; #server_name 192.168.1.11; # favicon配置 #location = /favicon.ico { # alias /home/chengdong/html/web-resoures/favicon.ico; # access_log off; # log_not_found off; # expires 30d; #} # 确保fancyindex文件可以通过web访问 location /fancyindex/ { alias /home/chengdong/upload/fancyindex/; } location / { root /home/chengdong/upload/; allow all; # 允许所有IP访问 # FancyIndex 配置 fancyindex on; fancyindex_exact_size off; fancyindex_localtime on; # fancyindex_name_length 255; fancyindex_directories_first on; # 目录优先显示 fancyindex_show_path off; # 不显示路径 # 我是把fancyindex文件夹存放在/home/chengdong/upload/fancyindex 下面的,上面配置了/fancyindex转发 # 自定义头尾文件(需要注意:我的访问是ip:端口/fancyindex/header.html直接能访问地址,所以我配置/fancyindex/header.html,要看自己存放在路径下,否则404) fancyindex_header "/fancyindex/header.html"; fancyindex_footer "/fancyindex/footer.html"; fancyindex_ignore "fancyindex"; # 允许远程推送 dav_methods PUT; create_full_put_path on; } }

6、检测和重启

nginx -t # 测试配置 systemctl restart nginx

注意:检查 SELinux 设置,不能是Enforcing模式

# 检查 SELinux 状态
getenforce
# 临时禁用
setenforce 0
http://www.jsqmd.com/news/1174775/

相关文章:

  • Midjourney景深不自然?92.6%的失败源于这1个被忽略的镜头参数——详解f-stop、sensor-size与--zoom的三维耦合逻辑
  • Unity Avatar Mapping 配置全解:从原理到.ht文件复用
  • BG3ModManager技术解析:博德之门3模组管理的核心原理与实战应用
  • 图像融合技术革命:Qwen-Edit-2509与Fusion Lora如何解决AI视觉合成的三大难题
  • 终极解密:5分钟快速掌握unluac Lua反编译工具完整教程
  • 欧米茄中国官方售后服务中心|网点地址与售后电话权威信息声明(2026年7月最新) - 欧米茄官方服务中心
  • TS2007FC与PIC18F4680在嵌入式音频处理中的高效应用
  • 0 基础入门React Native鸿蒙跨平台开发:PixelRatio 可以获取到设备的像素密度和字体缩放比
  • CursorWheelLayout性能优化指南:避免内存泄漏的3个最佳实践
  • 免费在线GPX编辑器gpx.studio:快速编辑GPS轨迹文件的专业工具
  • 龍魂系统 · 价值观底座 · 中华根声明 v1.0
  • Unity 2D RPG梦幻场景素材包:从导入到实战的完整开发指南
  • Study Experience (暑假篇 4)
  • Codex MCP Server 配置教程:让 Codex 连接文档、浏览器和开发工具
  • Arduino IDE 2.2.1 配置 TFT_eSPI 库:3个关键文件修改与240x240屏幕驱动避坑指南
  • 3步解决Vision Transformer性能瓶颈:pytorch-image-models实战指南
  • 杭州百达翡丽回收价格查询及各大回收平台实测排行(2026年7月最新) - 百达翡丽服务中心
  • 如何快速配置ComfyUI-Impact-Pack:面向初学者的完整指南
  • SolidWorks 2020-2025 全版本小金球开启:N卡/A卡 3步注册表修改法
  • IntelliJ IDEA 2024.1 + Maven Profile:3种环境切换方式与常见失效排查
  • 仅限首批500名开发者获取:LLM-Ops团队封存2年的级联调用性能基线报告(含Qwen/GLM/Claude三系Agent压测数据)
  • 现在似乎所有广告都会有“广告”这个标识
  • 【仅剩最后200份】Midjourney氛围工程手册(含独家LUT预设包+12类经典影视氛围Prompt模板)
  • 5分钟实现《原神》帧率自由:终极性能释放方案
  • macbook批量添加视频字幕?5款自动加字幕横评实测
  • prompt-ops扩展开发:创建自定义优化策略的开发者指南
  • 如何用KLayout实现芯片版图设计:从新手到专家的完整指南
  • 湖北大学小自考本科行政管理专业 2026 年招生简章【在职人员专属・官方助学点发布】 - 湖北找学校
  • 基于Bluetooth 5.4与STM32的无线音频系统设计
  • 0 基础入门React Native鸿蒙跨平台开发:Platform 模块检测运行时环境并实现跨平台适配的核心工具