-
Notifications
You must be signed in to change notification settings - Fork 604
Open
Description
批量替换jsdelivr资源镜像
前提:
- 你需要一台海外服务器
- 使用 Nginx
如果没有条件,请看最后一行。
对于 Linux / macOS 系统,运行:
sed -i "s/cdn.jsdelivr.net/jsdelivr.example.com/g" `grep -rl 'cdn.jsdelivr.net' Path/To/wp-content/themes/Sakura`Path/To/wp-content/themes/Sakura 自行替换成你的路径,可通过命令 pwd 获取当前路径
对于 Windows 系统,以管理员身份启动 PowerShell(PowerShell 5 以上,PowerShell 7下载),运行:
Get-ChildItem -Path C:\Path\To\Sakura -File -Recurse | Foreach-Object {
(Get-Content $_.PSPath) -Replace 'cdn.jsdelivr.net', 'jsdelivr.example.com' | Set-Content $_.PSPath
}C:\Path\To\Sakura 自行替换成你的路径,可通过命令 pwd 获取当前路径
以上的 jsdelivr.example.com 需要自行替换成自己的 jsdelivr 镜像域名,镜像配置如下(Nginx):
# 缓存路径配置
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=CACHE:10m inactive=7d max_size=1g;
# referer 白名单
map $http_referer $jsdelivr_allow_referer {
default 0;
"~example.com" 1;
"~example2.com" 1;
}
map $jsdelivr_allow_referer $jsdelivr_disallow_referer {
0 1;
1 0;
}
server {
listen 443 ssl http2;
server_name jsdelivr.example.com;
# ssl 配置
ssl_certificate ~/.acme.sh/mashiro/fullchain.cer;
ssl_certificate_key ~/.acme.sh/mashiro/mashiro.key;
ssl_session_timeout 5m;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!MEDIUM:!LOW:!aNULL:!NULL:!SHA;
ssl_prefer_server_ciphers on;
ssl_session_cache shared:SSL:10m;
# 关闭日志
access_log off;
# 指定 DNS
resolver 8.8.8.8;
if ($jsdelivr_disallow_referer) {
return 403 "The referer domain is not allowed to access this resource.";
}
location / {
proxy_redirect off;
proxy_pass https://fastly.jsdelivr.net;
proxy_cache_revalidate on;
proxy_set_header Host cdn.jsdelivr.net;
proxy_cache CACHE;
# 客户端的缓存时长
proxy_cache_valid 200 1h;
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
proxy_cache_lock on;
# 服务器端的缓存时长
expires 1h;
}
}以上需要在能正常访问 jsdelivr 的服务器上配置。如果确实没有条件,需要使用我的镜像,请通过QQ联系我。
其他反向代理方案:
huangguiniab and Limour-dev
Metadata
Metadata
Assignees
Labels
No labels