3.0 KiB
3.0 KiB
+++ 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。但根据相关法规,网站发布到公网需要添加 ICP 备案信息。经过多方探索,最终找到一个优雅的解决方案 - 使用 jsloader 插件进行添加。
解决方案
在研究过程中,遇到了几种常见方案:
- Nginx 反向代理添加(不支持 PHP 动态页面)
- 修改 Nextcloud 源码(升级后会丢失修改)
- 使用 jsloader 插件(推荐方案)
具体步骤
- 在 Nextcloud 应用商店安装
jsloader插件 - 使用管理员账号登录 Nextcloud
- 进入
管理设置 --> JavaScript loader - 在代码输入框中添加以下内容:
// 自动在页脚添加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 需要替换为实际的备案编号
- 代码会在登录页、分享页和首页等位置显示备案信息