起因
我在使用netlify部署博客后,经过测试速度,我觉得作为一款非国内产品速度相当不错
所以我想到了我部署在vercel的jsd反代
如果我把反代部署在netlify那么cdn的速度会有提升
说干就干
ps:如果你不想看我叨叨,你可以点击跳转到代码处直接查看代码使用
查阅文档
打开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 | [[redirects]] |
然后把这个仓库上传到github
之后我们点击这里在netlify新建一个项目并且选择已经上传到github仓库
然后等待部署完成即可
完结撒花👏
条评论