{"slug":"netlify-vercel-proxy","title":"Netlify、Vercel反代网站","description":"会用Netlify，家宽建站不是梦！","coverImage":"https://b.acofork.com/img/netlify-vercel-proxy-nvp.webp","coverWidth":1600,"coverHeight":900,"date":"2025-04-03","tags":["网络"],"pinned":false,"wordCount":450,"html":"<h2 id=\"原理思路\">原理思路</h2><p>现阶段大部分家宽拿不到公网IPv4，但是可以拿到公网IPv6，借助Netlify做一个v6 -&gt; v4的回源就可以让所有人都访问到你的站点了。同时这也是一个Netlify的通用反代教程。本文还教了Vercel的通用反代教程，不过这玩意在2025年仍然不支持IPv6，只能拿来反代小黄站了ToT</p>\n<h2 id=\"正式开始\">正式开始</h2><h3 id=\"netlify篇\">Netlify篇</h3><p>首先前往 <a href=\"https://app.netlify.com/\" target=\"_blank\" rel=\"noopener noreferrer\">https://app.netlify.com/</a> 注册账号。（注意！最好使用谷歌邮箱去注册，其他方式注册可能会出现什么你的账号需要验证/激活，然后巴拉巴拉很麻烦）\n接下来去Github开一个新仓库，根目录创建一个 <code>netlify.toml</code>。在其中写入</p>\n<div class=\"markdown-code\" data-language=\"toml\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path></svg><span>toml</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-toml\"><span class=\"hljs-section\">[[redirects]]</span>\n  <span class=\"hljs-attr\">from</span> = <span class=\"hljs-string\">\"/*\"</span>\n  <span class=\"hljs-attr\">to</span> = <span class=\"hljs-string\">\"http://反代域名:反代端口/:splat\"</span>\n  <span class=\"hljs-attr\">status</span> = <span class=\"hljs-number\">200</span>\n  <span class=\"hljs-attr\">force</span> = <span class=\"hljs-literal\">true</span></code></pre></div><p>注意，端口后面的斜杠一定不要丢！\n家宽v6网站建议搭配DDNS食用\n接下来回到 <a href=\"https://app.netlify.com/\" target=\"_blank\" rel=\"noopener noreferrer\">https://app.netlify.com/</a> 创建一个新项目，导入你刚创建的Github项目，部署即可\n最后绑定一下你的域名，完成！</p>\n<h3 id=\"vercel篇\">Vercel篇</h3><p>首先前往 <a href=\"https://vercel.com/\" target=\"_blank\" rel=\"noopener noreferrer\">https://vercel.com/</a> 注册并登录你的账号\n电脑安装Nodejs，我们需要用到npm\n安装Vercel CLI</p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">npm i -g vercel</code></pre></div><p>登录Vercel CLI</p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">vercel login</code></pre></div><p>找个地方（比如桌面）创建一个你随意命名的文件夹，然后在其中创建一个你随意命名的.json文件，其中写入。<strong>注意，目前Vercel不支持反代IPv6！！！</strong></p>\n<div class=\"markdown-code\" data-language=\"json\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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=\"M8 3H7a2 2 0 0 0-2 2v5a2 2 0 0 1-2 2 2 2 0 0 1 2 2v5c0 1.1.9 2 2 2h1\"></path><path d=\"M16 21h1a2 2 0 0 0 2-2v-5c0-1.1.9-2 2-2a2 2 0 0 0-2-2V5a2 2 0 0 0-2-2h-1\"></path></svg><span>json</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-json\"><span class=\"hljs-punctuation\">{</span>\n    <span class=\"hljs-attr\">\"version\"</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-number\">2</span><span class=\"hljs-punctuation\">,</span>\n    <span class=\"hljs-attr\">\"routes\"</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-punctuation\">[</span>\n      <span class=\"hljs-punctuation\">{</span><span class=\"hljs-attr\">\"src\"</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">\"/(.*)\"</span><span class=\"hljs-punctuation\">,</span><span class=\"hljs-attr\">\"dest\"</span><span class=\"hljs-punctuation\">:</span> <span class=\"hljs-string\">\"https://反代域名:端口\"</span><span class=\"hljs-punctuation\">}</span>\n    <span class=\"hljs-punctuation\">]</span>\n<span class=\"hljs-punctuation\">}</span></code></pre></div><p>然后部署</p>\n<div class=\"markdown-code\" data-language=\"text\"><div class=\"markdown-code-header\"><span class=\"markdown-code-language\"><svg class=\"code-language-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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=\"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z\"></path><path d=\"M14 2v5a1 1 0 0 0 1 1h5\"></path><path d=\"M10 9H8\"></path><path d=\"M16 13H8\"></path><path d=\"M16 17H8\"></path></svg><span>text</span></span><button type=\"button\" class=\"code-block-copy\" aria-label=\"复制代码\" title=\"复制代码\"><svg class=\"code-block-copy-icon\" aria-hidden=\"true\" width=\"16\" height=\"16\" 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\"><rect width=\"14\" height=\"14\" x=\"8\" y=\"8\" rx=\"2\" ry=\"2\"></rect><path d=\"M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2\"></path></svg></button></div><pre><code class=\"hljs language-text\">verceL -A 你随意命名的.json --prod</code></pre></div><p>最后绑定一下你的域名，完成！</p>\n","toc":[{"id":"原理思路","text":"原理思路","depth":2},{"id":"正式开始","text":"正式开始","depth":2},{"id":"netlify篇","text":"Netlify篇","depth":3},{"id":"vercel篇","text":"Vercel篇","depth":3}]}