抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

起因

我在使用netlify部署博客后,经过测试速度,我觉得作为一款非国内产品速度相当不错

https://cdn.chuqis.com/img/35b2aaa74553ddcf3b4e9765d2a3df0b.jpg

所以我想到了我部署在vercel的jsd反代
如果我把反代部署在netlify那么cdn的速度会有提升
说干就干

ps:如果你不想看我叨叨,你可以点击跳转到代码处直接查看代码使用

需要的东西

一个netlify账号

https://cdn.chuqis.com/img/4c8a395ea13de4893afb0921e74afeef.jpg

一个github账号

查阅文档

打开netlify的文档查看

格式

找到了路由设置的相关内容后可以看到这些内容和格式

If you specify your redirect rules in your Netlify configuration file, you can use a more structured configuration format with additional capabilities such as signed proxy redirects. In a netlify.toml file, we use TOML’s array of tables to specify each individual redirect rule. The following keywords are available:

from: The path you want to redirect.

to: The URL or path you want to redirect to.

status: The HTTP status code you want to use in that redirect; 301 by default.

force: Whether to override any existing content in the path or not; false by default. Visit the shadowing instructions for more details.

query: Query string parameters REQUIRED to match the redirect. Visit the query parameters instructions for more details.

conditions: Conditions to match the redirect, including country, role, and cookie presence conditions.

headers: Additional request headers to send in proxy redirects.

signed: Name of an environment variable for signed proxy redirects.

目录反代目录匹配

因为反代jsd同时需要反代jsd目录下的所有文件,所以这里需要有一个路径匹配

原文如下

An asterisk indicates a splat that will match anything that follows it.

You can use the splat in your rewrites or redirects like this:

/news/* /blog/:splat

This would redirect paths like /news/2004/01/10/my-story to /blog/2004/01/10/my-story.

所以我需要在 from的/后面添加* to的/后面添加:splat

实践代码

这里我需要http返回状态码为200

这样我的国内服务器就能再次反代netlify的cdn

整合完上面的设置配置就是这样了

这里我们需要把下面的代码放在新建名为 netlify.toml的文件中

注意这里的文件必须在仓库的根目录

1
2
3
4
5
6
[[redirects]]
from = "/*"
to = "https://cdn.jsdelivr.net/:splat"
status = 200
force = true
headers = {X-From = "Netlify"}

然后把这个仓库上传到github

之后我们点击这里在netlify新建一个项目并且选择已经上传到github仓库

然后等待部署完成即可

完结撒花👏

推荐文章(由hexo文章推荐插件驱动)

评论