Closed mengzai-c closed 1 year ago
https和svn,git都指向了github.com的相关资源 如果你的网络不能正常访问github.com的话,基本上很多功能都不能使用,可能影响armbian的正常使用。可能连armbian-config的基本配置都打不开。 你的问题不是https能解决的,你的设备不能访问github.com是问题。我也没有镜像站的资源,只有github.com的一个资源。
是这样,我想使用https来代替是因为它可以直接使用镜像站来达到一劳永逸的效果,如果使用SVN则不可使用采用CloudFlare搭建的Github镜像站,因为免费用户用不了特殊端口 这是我的镜像站以前是用了镜像docker hub的,打开速度是相当快的,使用镜像的方式会非常方便
这是CloudFlare Workers的镜像代码 还有这是我以前经常用的镜像站https://hub.nuaa.cf/ 打开速度也是相当快的
// 反代目标网站.
const upstream = 'github.com'
// 反代目标网站的移动版.
const upstream_mobile = 'github.com'
// 访问区域黑名单(按需设置).
const blocked_region = ['TK']
// IP地址黑名单(按需设置).
const blocked_ip_address = ['0.0.0.0', '127.0.0.1']
// 路径替换.
const replace_dict = {
'$upstream': '$custom_domain',
'//archiveofourown.org': ''
}
addEventListener('fetch', event => {
event.respondWith(fetchAndApply(event.request));
})
async function fetchAndApply(request) {
const region = request.headers.get('cf-ipcountry').toUpperCase();
const ip_address = request.headers.get('cf-connecting-ip');
const user_agent = request.headers.get('user-agent');
let response = null;
let url = new URL(request.url);
let url_host = url.host;
if (url.protocol == 'http:') {
url.protocol = 'https:'
response = Response.redirect(url.href);
return response;
}
if (await device_status(user_agent)) {
var upstream_domain = upstream;
} else {
var upstream_domain = upstream_mobile;
}
url.host = upstream_domain;
if (blocked_region.includes(region)) {
response = new Response('Access denied: WorkersProxy is not available in your region yet.', {
status: 403
});
} else if(blocked_ip_address.includes(ip_address)){
response = new Response('Access denied: Your IP address is blocked by WorkersProxy.', {
status: 403
});
} else{
let method = request.method;
let request_headers = request.headers;
let new_request_headers = new Headers(request_headers);
new_request_headers.set('Host', upstream_domain);
new_request_headers.set('Referer', url.href);
let original_response = await fetch(url.href, {
method: method,
headers: new_request_headers
})
let original_response_clone = original_response.clone();
let original_text = null;
let response_headers = original_response.headers;
let new_response_headers = new Headers(response_headers);
let status = original_response.status;
new_response_headers.set('cache-control' ,'public, max-age=14400')
new_response_headers.set('access-control-allow-origin', '*');
new_response_headers.set('access-control-allow-credentials', true);
new_response_headers.delete('content-security-policy');
new_response_headers.delete('content-security-policy-report-only');
new_response_headers.delete('clear-site-data');
const content_type = new_response_headers.get('content-type');
if (content_type.includes('text/html') && content_type.includes('UTF-8')) {
original_text = await replace_response_text(original_response_clone, upstream_domain, url_host);
} else {
original_text = original_response_clone.body
}
response = new Response(original_text, {
status,
headers: new_response_headers
})
}
return response;
}
async function replace_response_text(response, upstream_domain, host_name) {
let text = await response.text()
var i, j;
for (i in replace_dict) {
j = replace_dict[i]
if (i == '$upstream') {
i = upstream_domain
} else if (i == '$custom_domain') {
i = host_name
}
if (j == '$upstream') {
j = upstream_domain
} else if (j == '$custom_domain') {
j = host_name
}
let re = new RegExp(i, 'g')
text = text.replace(re, j);
}
return text;
}
async function device_status (user_agent_info) {
var agents = ["Android", "iPhone", "SymbianOS", "Windows Phone", "iPad", "iPod"];
var flag = true;
for (var v = 0; v < agents.length; v++) {
if (user_agent_info.indexOf(agents[v]) > 0) {
flag = false;
break;
}
}
return flag;
}
Device Information | 设备信息
Armbian Version | 系统版本
Describe the bug | 问题描述 All issues will only remain open for one week to prioritize resolving them. After that period, they will be closed but can still continue to be discussed in the thread. 所有的问题都只保留一周的开启状态供重点关注解决,超时将关闭,但仍然可以长期继续跟帖讨论。
Please provide a detailed description of the issue and, if necessary, attach a screenshot. 详细描述问题,并在必要时附上屏幕截图。 一直无法更新,尝试了改Hosts和SNI都更不了,希望加一个镜像参数通过https直接从镜像站更新。😊