Files
myblog/content/posts/configure-nextcloud-icp.md
2025-10-28 08:41:50 +08:00

3.1 KiB
Raw Blame History

+++ title = "Nextcloud配置ICP备案信息" date = "2025-10-27T16:16:17+08:00" author = "Gordon" tags = ["nextcloud", "icp", "备案"] keywords = ["nextcloud", "icp备案", "公安备案", "jsloader"] description = "通过 jsloader 插件为 Nextcloud 添加 ICP 备案信息和公安备案号的详细教程" showFullContent = false readingTime = true hideComments = false +++

Nextcloud 配置 ICP 备案信息

背景

最近购买了腾讯云轻量级服务器计划将家庭云盘部署到公网访问避免每次都需要使用VPN去链接。众所周知网站发布到公网需要添加备案信息。找了多个大神的方案最终找到一个比较优雅的解决方案 - 使用 nextcloud的jsloader 插件进行添加。

解决方案

折腾了一段时间,尝试了几个方案:

  • Nginx 反向代理添加(不支持 PHP 动态页面)
  • 修改 Nextcloud 源码修改i10n的翻译文件把法律声明和隐私政策改成ICP但升级版本后会被👏
  • 使用 jsloader 插件(推荐)

具体步骤

  1. 在 Nextcloud 应用商店安装 jsloader 插件
  2. 使用管理员账号登录 Nextcloud
  3. 进入 管理设置 --> JavaScript loader
  4. 在代码输入框中添加以下内容:
// 自动在页脚添加ICP与公安备案号
function add_beian_num(inclass) {
  // === 修改为你自己的备案号 ===
  const icp_num = "湘ICP备xxxxxxx号-1";
  const ga_num = "京公网安备xxxxxxxxx号";

  // 查找页面 footer
  const footers = document.querySelectorAll("footer");
  if (!footers || footers.length === 0) return;

  // 可选样式类
  const addclass = inclass ? ` class="${inclass}"` : "";

  // 构造插入内容
  // 公安备案链接修改为匹配自己的备案号
  const html = `
    <p${addclass} style="font-weight:300;text-align:center;margin-top:8px;">
      <a href="https://beian.miit.gov.cn" target="_blank" rel="nofollow" style="color:#888;text-decoration:none;">
        ${icp_num}
      </a>
        
      <a href="https://www.beian.gov.cn/portal/registerSystemInfo?recordcode=11010502000001"
         target="_blank" rel="nofollow" style="color:#888;text-decoration:none;">
        ${ga_num}
      </a>
    </p>
  `;

  // 插入备案号
  footers[0].insertAdjacentHTML("beforeend", html);
}

// 页面加载完成后执行
window.addEventListener("load", () => {
  const uri = window.location.pathname;
  const parts = uri.split("/");

  // 登录页或分享页时插入备案信息
  if (parts[1] === "login" || (parts[1] === "index.php" && parts[2] === "login")) {
    add_beian_num("info");
  } else if (parts[1] === "s" || (parts[1] === "index.php" && parts[2] === "s")) {
    add_beian_num();
  } else if (parts.length === 1 || parts[1] === "") {
    // 首页等其他页面也显示
    add_beian_num();
  }
});

注意事项

  • 请将代码中的备案号替换为你实际的备案信息
  • 公安备案链接中的 recordcode 需要替换为实际的备案编号
  • 代码会在登录页、分享页和首页等位置显示备案信息

参考来源