{"slug":"shorter-url","title":"无需服务器！从零教你自建一个短链服务！","description":"你是否有一个短域名？没有也没关系，马上教你从域名开始搭建一个短链服务！","coverImage":"https://b.acofork.com/img/shorter-url-shorter-url.webp","coverWidth":542,"coverHeight":355,"date":"2026-01-09","tags":["服务器"],"pinned":false,"wordCount":305,"html":"<h2 id=\"视频\">视频</h2><p><a href=\"https://www.bilibili.com/video/BV1BCi1B7E1q/\" target=\"_blank\" rel=\"noopener noreferrer\">https://www.bilibili.com/video/BV1BCi1B7E1q/</a></p>\n<h2 id=\"demo\">Demo</h2><p><a href=\"https://2x.nz/s\" target=\"_blank\" rel=\"noopener noreferrer\">https://2x.nz/s</a></p>\n<h2 id=\"拿域名\">拿域名！</h2><p>我们需要一个短域名，来作为我们的短链服务的入口</p>\n<p>我们可以前往这些地方购买短域名，建议后缀 <code>.nz</code> <code>.mk</code> <code>.im</code> ，建议2-3位长度的域名</p>\n<ul>\n<li><a href=\"https://www.spaceship.com/zh/\" target=\"_blank\" rel=\"noopener noreferrer\">迈向未来 - Spaceship</a></li>\n<li><a href=\"https://porkbun.com/\" target=\"_blank\" rel=\"noopener noreferrer\">porkbun.com | An oddly satisfying experience.</a></li>\n<li><a href=\"https://www.quyu.net/\" target=\"_blank\" rel=\"noopener noreferrer\">【趣域网】域名注册网站哪个好_注册域名查询购买_whois信息查询_域名交易网_ - 趣域网</a></li>\n</ul>\n<h2 id=\"基础思路\">基础思路</h2><p>Cloudflare Page/Worker的重定向文件提供了基于文件的重定向功能，参考 <a href=\"/posts/cfpage-redirect/\">这篇文章</a></p>\n<p>接下来我们再利用 Cloudflare Worker 连接Github帮我们去更新这个文件，顺便搓一个前端出来让用户能够生成短链即可</p>\n<h2 id=\"防护措施\">防护措施</h2><aside class=\"markdown-alert markdown-alert--caution\"><div class=\"markdown-alert-title\"><svg class=\"markdown-alert-icon\" aria-hidden=\"true\" width=\"18\" height=\"18\" viewbox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M12 16h.01\"></path><path d=\"M12 8v4\"></path><path d=\"M15.312 2a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586l-4.688-4.688A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2z\"></path></svg><span>注意</span></div><div class=\"markdown-alert-body\"><p>必须在最终重定向时不直接重定向到业务域名，需要配置中间页，否则你的域名一定会在后期被举报为 <strong>滥用/钓鱼/诈骗网站</strong></p>\n</div></aside><ul>\n<li>重定向文件限制静态重定向 <strong>2000</strong> ，动态重定向 <strong>100</strong></li>\n<li>单行字符串不超过 <strong>1024</strong></li>\n</ul>\n<h2 id=\"服务架构图\">服务架构图</h2><p><img src=\"https://b.acofork.com/img/shorter-url-MermaidChart-Createcomplexvisualdiagramswithtext-2026-01-09-031619.webp\" alt=\"\" width=\"2534\" height=\"8192\" loading=\"eager\" decoding=\"async\" /></p>\n","toc":[{"id":"视频","text":"视频","depth":2},{"id":"demo","text":"Demo","depth":2},{"id":"拿域名","text":"拿域名！","depth":2},{"id":"基础思路","text":"基础思路","depth":2},{"id":"防护措施","text":"防护措施","depth":2},{"id":"服务架构图","text":"服务架构图","depth":2}]}