通过国内网络环境下载一些东西速度会十分慢,着实让人抓狂,在此记录一下可用的镜像源与方法,以备不时之需。
下载镜像
Python Node.js NPM Electron等
https://npm.taobao.org/mirrors
Linux源
清华大学
Ubuntu: https://mirrors.tuna.tsinghua.edu.cn/help/ubuntu
Debian: https://mirrors.tuna.tsinghua.edu.cn/help/debian
CentOS: https://mirrors.tuna.tsinghua.edu.cn/help/centos
Raspbian:https://mirrors.tuna.tsinghua.edu.cn/help/raspbian
阿里云
https://developer.aliyun.com/mirror
PyPI源
# 升级 pip 到最新的版本 (>=10.0.0) 后进行配置
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U
# 设置清华源为默认
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 设置阿里源为默认
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple
GitHub
推荐使用Cloudflare Workers搭建加速服务,项目地址
我搭建的服务地址是 https://p.ooe.ooo
代码:
function getTargetUrl(url) {
const re = new RegExp('^https?:\/\/.+?\/(?:https?:\/\/)?(.+$)');
return url.replace(re, 'https://$1');
}
// location返回相对地址的情况 https://httpbin.org/redirect/10
function urlMerge(origin, path) {
try {
const url = new URL(path);
return url.href;
} catch (e) {
const url = new URL(origin);
return url.origin + path;
};
}
function responseClean(res) {
let headers = new Headers(res.headers);
headers.delete('x-frame-options')
headers.delete('content-security-policy')
headers.delete('content-security-policy-report-only')
headers.delete('clear-site-data')
return new Response(res.body, { status: res.status, headers: headers })
}
async function getHttpContent(url, request) {
// get response
const newRequest = new Request(url, {
headers: request.headers,
body: request.body,
method: request.method,
redirect: 'manual'
});
console.log(url);
let res = await fetch(newRequest);
if (res.headers.has('location')) {
url = urlMerge(url, res.headers.get('location'));
return getHttpContent(url, request);
}
return responseClean(res);
}
async function handleRequest(request) {
const url = getTargetUrl(request.url);
if (url === request.url) {
return new Response('示例格式:\n' + url + 'https://www.google.com', { status: 502 });
}
return getHttpContent(url, request);
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});
jsdelivr
使用jsdelivr加速raw.githubusercontent.com域名
# 使用格式
https://cdn.jsdelivr.net/gh/{user}/{project@release}/{file}
# 未加速
https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjx-annoyance.txt
# 使用jsdelivr加速后的网址
https://cdn.jsdelivr.net/gh/cjx82630/cjxlist@master/cjx-annoyance.txt
cnpmjs
已失效, 请改用其他方案
使用cnpmjs加速clone
# 将网址部分github.com修改为github.com.cnpmjs.org
# 未加速
git clone https://github.com/Fmstrat/winapps.git
# 使用cnpmjs加速
git clone https://github.com.cnpmjs.org/Fmstrat/winapps.git